[英]How can I extract forum post's author with jsoup?
<div class="username_container">
<div id="yui-gen11" class="popupmenu memberaction">
<a id="yui-gen13" class="username offline popupctrl" href="member.php?u=276113" title="PilotPhill is offline"><strong>**PilotPhill**</strong></a>
<ul id="yui-gen12" class="popupbody memberaction_body">
<li class="left">
I am trying to extract the author names of a forum thread using jsoup. 我正在尝试使用jsoup提取论坛主题的作者姓名。 It is the name inside the strong tags. 它是强标签内的名称。 I have tried close to everything and just can't get it. 我已经尝试了几乎所有内容,但收不到。
Any tips? 有小费吗? I've been using jSoup.select() but if there are other methods, I'd be happy to try. 我一直在使用jSoup.select(),但是如果还有其他方法,我很乐意尝试。
You just have to use Document.select
as you already found out. 您只需要使用Document.select
就可以了。
Document doc = Jsoup.connect("http://www.foo.com").get();
Elements usernames = doc.select("a.username strong");
for (Element username: usernames) {
System.out.println("found username: " + username.text();
}
a.username strong
means: tags strong
inside tag a
with attribute class
having the value username
as in : a.username strong
意思是:在标签a
内标记strong
,其中标签a
具有属性class
,其username
为username
如:
<a id="yui-gen13" class="username offline popupctrl"
href="member.php?u=276113" title="PilotPhill is offline">
<strong>**PilotPhill**</strong>
</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.