<div class="Class-feedbacks">
<div class="grading class2">
<div itemtype="http://xx.edu/grading" itemscope="" itemprop="studentgrading">
<div class="rating">
<img class="passportphoto" width="1500" height="20" src="http://greg.png" >
<meta content="4.0" itemprop="gradingvalue">
</div>
</div>
<meta content="2012-09-08" itemprop="gradePublished">
<span class="date smaller">9/8/2012</span>
</div>
<p class="review_comment feedback" itemprop="description">Greg is one the smart person in his batch</p>
</div>我想印:
date: 2012-09-08
Feedback : Greg is one the smart person in his batch我能够按照- Jsoup getting a hyperlink from li上的建议使用这个
doc.select( divn .)并得到课堂反馈。
如何使用select命令获取上述值的值?
发布于 2012-09-16 09:02:59
若要获取属性值,请使用attr方法。例如。
Elements elements = doc.select("meta");
for(Element e: elements)
System.out.println(e.attr("content"));发布于 2015-03-07 00:44:03
在一个选择...have中,您尝试了逗号组合器",“?http://jsoup.org/apidocs/org/jsoup/select/Selector.html
Elements elmts = doc.select("div.Class-feedbacks meta, p")
Element elmtDate = elmts.get(0);
System.out.println("date: " + elmtDate.attr("content"));
Element elmtParag = elmts.get(1);
System.out.println("Feedback: " + elmtParag.text()); 您应该返回列表中的两个元素,日期和选择后的反馈。
发布于 2015-04-24 04:07:37
这是一个老问题,我可能会迟到,但是如果其他人想知道如何轻松地完成这个任务,下面的代码将是有帮助的。
Document doc = Jsoup.parse(html);
// We select the meta tag whose itemprop property has value 'gradePublished'
String date = doc.select("meta[itemprop=gradePublished]").attr("content");
System.out.println("date: "+date);
// Now we select the text inside the p tag with itemprop value 'description'
String feedback = doc.select("p[itemprop=description]").text();
System.out.println("Feedback: "+feedback);https://stackoverflow.com/questions/12445539
复制相似问题