【发布时间】:2011-01-12 04:20:50
【问题描述】:
我最近遇到了一些关于 HtmlUnit 返回空值的问题,我正在寻求指导。我抓取网站第一行的每个结果都返回 null。我想知道是否有人可以
A)解释为什么他们可能返回 null
B)解释获取信息的更好方法(如果有的话)
这是我当前的代码(网址在源代码中):
client = new WebClient(BrowserVersion.FIREFOX_3)
client.javaScriptEnabled = false
def url = "http://www.hidemyass.com/proxy-list/"
page = client.getPage(url)
IpAddress = page.getFirstByXPath("//html/body/div/div/form/table/tbody/tr/td[2]").getValue()
println "IP Address is: $data" //returns null
//Port_Number is an Image
Country = page.getFirstByXPath("//html/body/div/div/form/table/tbody/tr/td[4][@class='country']/@rel").getValue()
println "Country abbreviation is: $Country"
//differentiate speed and connection by name of gif?
Type = page.getFirstByXPath("//html/body/div/div/form/table/tbody/tr/td[7]").getValue()
println "Proxy type is: $Type"
Anonymity = page.getFirstByXPath("//html/body/div/div/form/table/tbody/tr/td[8]").getValue()
println "Anonymity Level is: $Anonymity"
client.closeAllWindows()
现在我所有的 XPath 都返回 null 并且 .getValue() 显然在 null 上不起作用。
我还有关于 PORT 是图像应该怎么做的问题?有没有比下载它并尝试通过 OCR 解决它更好的选择?
旁注
这个站点没有任何意义,我只是在寻找一个我可以练习抓取的站点(最后一个我遇到了片段身份问题并且无法得到答案:HtmlUnit getByXpath returns null 和 @987654322 @)
【问题讨论】:
标签: html groovy screen-scraping htmlunit