2010-11-12 57 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("...")