html-content-extraction - HTTPBuilder - 如何获取网页的 HTML 内容?

标签 html-content-extraction httpbuilder

我需要提取网页的 HTML 我在 groovy 中使用 HTTPuilder,得到以下结果:

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"
 }
}

我得到的响应不包含我在浏览 www.google.com/search 的 html 源时看到的相同 html。事实上,它既不是 html,也不包含我在页面的 html 源代码中看到的相同信息。 我试过设置不同的标题(例如,headers.Accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8',标题。 accept = 'text/html',设置用户代理等),但结果是一样的。 如何使用 http 构建器获取 www.google.com/search(或任何网页)的 html?

最佳答案

为什么要使用httpBuilder?您可以改用

def url = "http://www.google.com/".toURL() 

println url.text`

提取网页内容

关于html-content-extraction - HTTPBuilder - 如何获取网页的 HTML 内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6816943/

相关文章:

grails - 使用 HttpBuilder 通过 SSL 上传文件

PHP - 如何在 Firefox 中获取主要的 HTML 内容,如阅读器模式

python - 提取维基百科文章的介绍部分,通过python

html - 如何从 HTML 中提取有意义的文本

groovy - 从 HTTP 请求获取纯 HTML

thread-safety - Grails HTTPBuilder 线程安全吗?

grails - Grails HTTBuilder请求错误

perl - 使用 TreeBuilder 在 Perl 中提取链接

grails - 如何将响应的读取器分配给从 httpbuilder 到 Controller 的变量