我正在阅读Rubyforge上socksify gem的文档。我已成功安装了gem,并且已成功运行此文档代码以测试我的本地实现是否可以复制它:
require 'socksify/http'
uri = URI.parse('http://rubyforge.org/')
Net::HTTP.SOCKSProxy('127.0.0.1', 9050).start(uri.host, uri.port) do |http|
http.get(uri.path)
end
# => #<Net::HTTPOK 200 OK readbody=true>
但我如何例如刮'http://google.com/'
,并获取HTML内容?我想解析它,例如Nokogiri是这样的:
Nokogiri::HTML(open("http://google.com/))
答案 0 :(得分:3)
require 'socksify/http'
http = Net::HTTP::SOCKSProxy(addr, port)
html = http.get(URI('http://google.de'))
html_doc = Nokogiri::HTML(html)