【发布时间】:2015-12-27 22:13:13
【问题描述】:
我正在尝试使用 JSoup 解析如下所示的结构。
<div class="bigClass">
<a href="foo.com"> Field 1</a>
<a href="bar.com"> Field 2</a>
<a href="baz.com"> Field 3</a>
</div>
现在,我正在使用以下代码获取 div 类“bigClass”的整个文本内容
doc = Jsoup.connect("http://foobar.com").userAgent(userAgent).timeout(1000).get();
price = doc.getElementsByClass("bigClass");
System.out.println(price.text());
无论<a> 类和 URL 如何,我怎样才能只获取第一个孩子(“字段 1”)?
BeautifulSoup python 的类似问题:Beautiful soup getting the first child
【问题讨论】: