[英]jsoup select elements
I'm trying to scrape a website for data using jsoup. 我正在尝试使用jsoup抓取网站以获取数据。 But having some problems with getting some text.
但是在获取文本时遇到一些问题。
Part of the html looks like this HTML的一部分看起来像这样
<p class="time">9:00</p>
which i can grab fine using the line of code: 我可以使用以下代码行抓紧:
Document doc = Jsoup.connect(url).get();
doc.select("p.time").text());
but the next bit of html looks like this: 但是html的下一部分看起来像这样:
<p class="date"><strong>FRIDAY 27<sup>th</sup></strong> JULY 2012</p>
Which i'm not sure how to get. 我不知道该怎么去。 Using the line:
使用该行:
doc.select("p.date").text());
just gets me an empty string. 只是给我一个空字符串。 I've tried variations of that (ie selecting "p.date" and then try date.select("strong")) but just keep coming up with a empty strings.
我已经尝试过变种(例如,选择“ p.date”,然后尝试date.select(“ strong”)),但是只是想出一个空字符串。
how do I go about getting that date text? 我该如何获取日期文本?
Unable to reproduce your problem. 无法重现您的问题。
Document doc = Jsoup.parse("<html><body><p class=\"date\"><strong>FRIDAY 27<sup>th</sup></strong> JULY 2012</p></body></html>");
String s = doc.select("p.date").text();
System.out.println(s);
This prints: "FRIDAY 27th JULY 2012" 打印:“ 2012年7月27日,星期五”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.