首页 > 解决方案 > Ruby HTTPclient:不推荐使用位置标头中的相对 URI

问题描述

我想抓取这样的网站:

 url = 'https://www.example.com/projects/search?scope=projects'
 content = @clnt.get_content(url,nil,CONF.header)
 doc = Nokogiri::HTML(content)

但我收到以下消息:

/projects/search?scope=projects: a relative URI in location header which is not recommended
'The field value consists of a single absolute URI' in HTTP spec
Cookie#domain returns dot-less domain name now. Use Cookie#dot_domain if you need "." at the beginning.

有谁知道如何处理它?

标签: rubyhttpclient

解决方案


据我所知,实现的get_content工作方式类似于get但也允许遵循重定向。在这种情况下,重定向是通过相对 URL 完成的,因此 gem 会产生警告。查看源代码


推荐阅读