2013-05-27 43 views
0

我想打印网页的用户评论由他们给出的评级一直以来,我尝试了下面的代码文本没有在Jsoup正常显示

Elements links = doc.select("p.s_desc,span.s_rating_overal"); 
    //Elements links1 = doc.select(); 
    //System.out.println(links.next()); 
    ListIterator iter= links.listIterator(); 
    while(iter.hasNext()) 
    { 
    //String test= iter.next().text(); 
    System.out.println("\n"+iter.next()); 
    System.out.println(iter.next()+"\n\n"); 


    } 

的问题是输出与磨磨蹭蹭标签。

<span class="s_rating_overal">5.3</span> 
<p class="s_desc">You don't need a load of explanation on why this phone changed 
the market and set the standard, though the ties to AT&amp;T and Apple are way 
too strong to truly enjoy this device. &nbsp;The screen and style are now a bit 
outdated and the lack of customization make you feel like you are a cow in the t 
he big heard of i ecosystem. &nbsp;The ui is still probably the best there is bu 
    t, come on its time for a face lift.</p> 

我怎样才能如果我使用iter.next()只得到文本之间标签提前

感谢。文本();,我收到以下错误

Crawler.java:44: cannot find symbol 
symbol : method text() 
location: class java.lang.Object 
      System.out.println("\n"+iter.next().text()); 
              ^
Crawler.java:45: cannot find symbol 
symbol : method text() 
location: class java.lang.Object 
      System.out.println(iter.next().text()+"\n\n"); 
             ^
2 errors 

回答

0

在您的代码中,iter.next()返回Element实例。然后,将Element实例与字符串连接起来,因此将调用toString()方法。

Element类的toString()方法返回标记以及内容。 如果你只想要元素的内容,你应该使用text()方法。

+0

如果我使用iter.next()。text()它显示错误... – Arun

+0

什么样的错误?你能发送堆栈跟踪吗? – mguillermin

+0

我给这个问题本身添加了错误plz look – Arun