1
我有一些python代理檢查器。Python代理檢查器,更改爲線程版本
,並加快支票,我決定改變到多線程版本,
和線程模塊首先對我來說,我是打了幾次轉換到線程版本
,尋找許多信息,但對新手python程序員來說並不那麼容易。
如果任何人都可以幫助我真的很感激!
在此先感謝!
import urllib2, socket
socket.setdefaulttimeout(180)
# read the list of proxy IPs in proxyList
proxyList = open('listproxy.txt').read()
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.yahoo.com') # <---check whether proxy alive
sock=urllib2.urlopen(req)
except urllib2.HTTPError, e:
print 'Error code: ', e.code
return e.code
except Exception, detail:
print "ERROR:", detail
return 1
return 0
for item in proxyList:
if is_bad_proxy(item):
print "Bad Proxy", item
else:
print item, "is working"
hi..yes..i知道排隊是安全的,我用不同的方法嘗試了幾次,但缺乏對線程的知識,我沒有運氣......謝謝 – paul 2009-12-07 09:52:19
這是頁尾頁的示例用'Queue'模塊文檔:http://docs.python.org/library/queue.html。適應你的任務是相當的功課。 – 2009-12-07 10:34:21