首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GetValue (JSoup)

GetValue (JSoup)
EN

Stack Overflow用户
提问于 2012-09-16 08:46:47
回答 3查看 899关注 0票数 0
代码语言:javascript
复制
<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>

我想印:

代码语言:javascript
复制
date: 2012-09-08
Feedback : Greg is one the smart person in his batch

我能够按照- Jsoup getting a hyperlink from li上的建议使用这个

doc.select( divn .)并得到课堂反馈。

如何使用select命令获取上述值的值?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-09-16 09:02:59

若要获取属性值,请使用attr方法。例如。

代码语言:javascript
复制
Elements elements = doc.select("meta");
for(Element e: elements)
  System.out.println(e.attr("content"));
票数 2
EN

Stack Overflow用户

发布于 2015-03-07 00:44:03

在一个选择...have中,您尝试了逗号组合器",“?http://jsoup.org/apidocs/org/jsoup/select/Selector.html

代码语言:javascript
复制
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()); 

您应该返回列表中的两个元素,日期和选择后的反馈。

票数 0
EN

Stack Overflow用户

发布于 2015-04-24 04:07:37

这是一个老问题,我可能会迟到,但是如果其他人想知道如何轻松地完成这个任务,下面的代码将是有帮助的。

代码语言:javascript
复制
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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12445539

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档