Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
764 views
in Technique[技术] by (71.8m points)

proxy - Grab and Rotate proxies in Python

I'm creating a bot to register in a webform, I need to grab proxies from certain websites like proxyscrap and download them into a text file. Then the python script runs the browser and defines then connect to the working and fastest one first.

Can I do that? If yes please provide me with the code


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have other method is free method not like proxyscrap. I suggest to use http-request-randomizer from here Link

Using it is so simple

from http_request_randomizer.requests.proxy import RequestProxy

req_proxy = RequestProxy()
pro=req_proxy.randomize_proxy()
pro1=str(pro).split(' ')[0]

Then use pro1 as a proxy for your request it will generate new proxy each time, or if you need to use a custom proxy then:

def is_bad_proxy(pip):    
try:
    proxy_handler = urllib2.ProxyHandler({'http': pip})
    opener = urllib2.build_opener(proxy_handler)
    opener.addheaders = [('User-agent', 'Mozilla/5.0')]
    urllib2.install_opener(opener)
    req=urllib2.Request('http://www.example.com')  # change the URL to test here
    sock=urllib2.urlopen(req)
except urllib2.HTTPError, e:
    print 'Error code: ', e.code
    return e.code
except Exception, detail:
    print "ERROR:", detail
    return True
return False

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...