I have the problem with Too many connection on mechanize and I wounder how I close a connection since I want to build a scraper with proxy.
我在mechanize上遇到了连接太多的问题,我不知道如何关闭连接,因为我想使用proxy构建一个刮刀。
I did find the
我确实发现
agent.shutdown
but for somereason I cant get that to work. any help ?
但有些事我做不到。任何帮助吗?
10.times {
minion = Mechanize.new { |mech|
mech.open_timeout = 15
mech.read_timeout = 15
}
minion.set_proxy '212.82.126.32', 80
page = minion.get("http://www.whatsmyip.org/")
proxy_ip_adress = page.parser.css('#ip').text
puts proxy_ip_adress
minion.shutdown
}
1 个解决方案
#1
2
I think you'll want to use a Mechanize#start block:
我想你会想用一个机械化#开始块:
10.times do
Mechanize.start do |minion|
minion.open_timeout = 15
minion.read_timeout = 15
minion.set_proxy '212.82.126.32', 80
page = minion.get("http://www.whatsmyip.org/")
proxy_ip_adress = page.parser.css('#ip').text
puts proxy_ip_adress
end
# minion definitely doesn't exist anymore
end
#1
2
I think you'll want to use a Mechanize#start block:
我想你会想用一个机械化#开始块:
10.times do
Mechanize.start do |minion|
minion.open_timeout = 15
minion.read_timeout = 15
minion.set_proxy '212.82.126.32', 80
page = minion.get("http://www.whatsmyip.org/")
proxy_ip_adress = page.parser.css('#ip').text
puts proxy_ip_adress
end
# minion definitely doesn't exist anymore
end