2014-11-23 106 views
0

我有这个页面,我想收集来自多个值:如何用Jsoup选择每个元素?

enter image description here

我已经尝试了多种不同的slectors,但我似乎无法让他们的工作,他们什么也不返回, 我发现这样的:

Elements eles = docWeather.select("rep:eq(0)"); 
String temp = eles.attr("f"); 

得到的7首个“F”的值,但我不能让行的其余部分是这样的块:

enter image description here

更新:我现在也尝试使用Phantomjs与WebDiver选择元素,它返回一个“没有这样的元素异常”?我使用的Xpath是:

WebElement weatherData = driver.findElement(By.xpath("//*[@id='collapsible4']")); 

为什么我无法选择此内容?

回答

1

尝试选择第一个period的所有reps

然后遍历Elements

Somethig像:

Elements eles = docWeather.select("location:eq(0) rep"); 
for (Element ele: select){ 
    String temp = eles.attr("f"); 
    System.out.println(temp);   
} 

我希望它可以帮助

PS:好的艺术品:)

+0

嗨,是由于那是什么我到底做的,但我仍然不知道为什么我无法选择任何常用选择器。无论如何感谢您的答案。 – 2014-11-25 20:43:57

+0

哈哈,你的照片描绘了千言万语!谢谢 – 2014-11-25 20:48:36