Document doc = Jsoup.connect("http://reviews.opentable.com/0938/9/reviews.htm").get();
Element part = doc.body();
Elements parts = part.getElementsByTag("span");
String attValue;
String html;
for(Element ent : parts)
{
if(ent.hasAttr("class"))
{
attValue = ent.attr("class");
if(attValue=="BVRRReviewText description")
{
System.out.println("\n");
html=ent.text();
System.out.println(html);
}
}
}
我正在为上述程序使用 Jsoup.jar。
我正在访问该网页,我的目标是打印在标签 <span class="BVRRReviewText description">text</span>
中找到的文本.
但没有任何内容作为输出打印出来。 String html
没有添加内容在程序中。但是attValue
正在获取span标签的所有属性值。
我一定哪里出错了?请指教。
最佳答案
if(attValue=="BVRRReviewText description")
应该是
if(attValue.equals("..."))
肯定吗?
这是 Java,不是 Javascript。
关于java - 使用 Jsoup.Jar 进行 HTML 解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4162533/