2014-04-07 131 views
1

如何从迭代器中获取url,我正在使用jsoup。 enter image description here如何从迭代器获取网址?

我试图做urls.add(ite.next().parentNode().attributes().asList().get(0).toString());但价值不是什么需要。

+1

你是如何得到这个迭代器?什么是迭代? 'asList()'对我来说看起来是可疑的;你应该通过名称获取属性,而不是通过它的位置。如果有像''这样的标签怎么办? –

+0

你有什么价值? – Vishrant

+0

David Conrad,迭代器 ite = table.select(“FONT [style = FONT-SIZE:10pt]”)。iterator();得到迭代器。我知道asList()不正确 – user2650128

回答

1

我建议您阅读如何从元素提取属性值此文档: http://jsoup.org/cookbook/extracting-data/attributes-text-html

还有从堆栈溢出本身这个例子: getting attribute value from Div tag through jSoup

像这样的东西应该解决您的问题:

Element link = doc.getElementById("yourlinkid"); 
String attr = link.attr("href"); 
System.out.println(attr); 

有不同的方式来找到你的链接使用不同的选择器。

+0

我使用的元素:元素表= doc.select(“table [width = 90%]”)。first(); 还需要使用:迭代器 ite = table.select(“FONT [style = FONT-SIZE:10pt]”)。iterator(); – user2650128

+0

这是一个有用的信息,但我不知道得到所需的值 – user2650128

+0

检查更新,选择你的链接元素,并从它的gert属性。 – eduardohl