multithreading - Python proxy checker, change to threaded version -


I have checked some dragon proxy.

And to accelerate the investigation, I decided the change version for multi-sequence,

and thread module is the first for me, I was tried several times the version < / P>

Thread and many information is to convert to look, but it is not so easy for newbie python programmers.

If someone can really appreciate me very much !!

Thanks in advance!

urlib2, socket socket.setdefaulttimeout (180) # proxyList proxyList = Read the list of Proxy IPs in open ('listproxy.txt') .read () Def is_bad_proxy (Pip): Try : Proxy_handler = urllib2.ProxyHandler: opener = urllib2.build_opener (proxy_handler) opener.addheaders = [('user-agent' ({'http' pip} ',' Mozilla / 5.0 ')] Urllib2.install_opener (openers) Req = urllib2.Request ('http://www.yahoo.com') # & lt; --- Check whether the proxy is alive except sock = urllib2.urlopen (req) urllib2.HTTPError, e: print 'error code:', except exception, expansion e.code return e.code: print "error:" , Expansion return 1 return for items in proxyList: if_bad_proxy (item): print "bad proxy", item other: print item, "working"

urllib2.install_opener () installs the function global opener, i.e. this thread is not secure I am its Do not call the opener.open () method instead of global urllib2.urlopen () function abuse. Also use the class from the queue queue module to hold the list of proxies to check. It's OK to use the rest of your code in threaded mode.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -