2010-11-12 54 views
1
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。HTML解析使用Jsoup.Jar

我正在访问该网页,我的目标是打印标签<span class="BVRRReviewText description">text</span>中的文本。

但是没有任何内容被打印为输出。在程序中没有添加到String html的内容。但attValue正在获取span标签的所有属性值。

我该在哪里出错?请指教。

回答

4
if(attValue=="BVRRReviewText description") 

应该

if(attValue.equals("..."))肯定?

这是Java,而不是Javascript。

+0

感谢....只是得到了解决? – LGAP 2010-11-12 08:58:51

0

变化

attValue=="BVRRReviewText description"

attValue.matches("...")