我需要提取网页的HTML 我使用HTTPuilder在Groovy中,做出如下得到:HTTPBuilder - 如何获取网页的HTML内容?
def http = new HTTPBuilder('http://www.google.com/search')
http.request(Method.GET) {
requestContentType = ContentType.HTML
response.success = { resp, reader ->
println "resp: " + resp
println "READER: " + reader
}
response.failure = { resp, reader ->
println "Failure"
}
}
我得到的回应,不包含相同的HTML,我可以看到,当我探讨www.google.com/search的html资源。事实上,它既不是html,也不包含我可以在页面的html源代码中看到的相同信息。 我试过设置不同的标题(例如,headers.Accept ='text/html,application/xhtml + xml,application/xml; q = 0.9,/; q = 0.8',headers.Accept ='text/html',seting用户代理等),但结果是一样的。 如何使用http构建器获取www.google.com/search(或任何网页)的html?