How to close a mechanized connection

I have a problem with too many connections to mechanize and I know how I am closing the connection since I want to build a scraper with a proxy.

I found

agent.shutdown

      

but for a while, I can't get this 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

}

      

+3


source to share


1 answer


I think you want to use the initial Mechanize # 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

      

+2


source







All Articles