0

What I want to do is this

I have a proxy list with ip|port

Now Mechanize is using those proxy and I have set

open_timeout = 20 
read_timeout = 20

What I want it todo is to retry, but it will retry with the same proxy even if I have "proxies = @proxies.order("RANDOM()").first" it will not load a new proxy, but instead it will load from cache

here is my code that I use :

begin
    proxies = @proxies.order("RANDOM()").first
    proxy_ip = proxies.ip
    proxy_port = proxies.port
    puts proxy_ip
    puts proxy_port

    agent = Mechanize.new
    agent.open_timeout = 20
    agent.read_timeout = 20
    agent.set_proxy(proxy_ip, proxy_port)


    page = agent.get("http://whatismyip.org/"
rescue
     puts "oh shit, error"
     retry

end
    doc = page.parser
    ip_ad = doc.css('span').text
    puts ip_ad

Now my question is how do I make it load a new proxy instead of using it from the cache

Cyrus Zei
  • 2,589
  • 1
  • 27
  • 37

1 Answers1

0

For anybody that comes here from google this is how I solved it

offset = rand(Proxy.count)
proxies = @proxies.offset(offset).first

I use the offset and it works like a charm and this is

begin page = minion.submit(form,button)

        rescue Mechanize::ResponseCodeError => e

            offset = rand(Proxy.count)
            proxies = @proxies.offset(offset).first
            proxy_ip = proxies.ip
            proxy_port = proxies.port
            puts proxy_ip
            puts proxy_port

            minion.open_timeout = 3.0
            minion.read_timeout = 3.0
            minion.cookie_jar.clear!
            minion.max_history = 0
            #minion.set_proxy(proxy_ip, proxy_port)

            sleep 5.0

            if page.parser.xpath('//h2[contains(@class,"name")]').text == "Ingen träff"
                puts "ingen träff"
            else
                puts "retrying"
                retry
            end

    end

Enjoy guys

Cyrus Zei
  • 2,589
  • 1
  • 27
  • 37