标签:
#!/usr/bin/env python
#coding:utf-8
#BLOG: blog.linuxeye.com
import urllib2
import re
import threading
import time
import MySQLdb
rawProxyList = []
checkedProxyList = []
#抓取代理网站
targets = []
for i in xrange(1,42):
target = r"http://www.proxy.com.ru/list_%d.html" % i
targets.append(target)
#抓取代理服务器正则
p = re.compile(r‘‘‘<tr><b><td>(\d+)</td><td>(.+?)</td><td>(\d+)</td><td>(.+?)</td><td>(.+?)</td></b></tr>‘‘‘)
#获取代理的类
class ProxyGet(threading.Thread):
def __init__(self,target):
threading.Thread.__init__(self)
self.target = target
def getProxy(self):
print "代理服务器目标网站: " + self.target
req = urllib2.urlopen(self.target)
result = req.read()
#print chardet.detect(result)
matchs = p.findall(result)
# print matchs
for row in matchs:
ip=row[1]
port =row[2]
addr = row[4].decode("cp936").encode("utf-8")
proxy = [ip,port,addr]
print proxy
rawProxyList.append(proxy)
def run(self):
self.getProxy()
#检验代理的类
class ProxyCheck(threading.Thread):
def __init__(self,proxyList):
threading.Thread.__init__(self)
self.proxyList = proxyList
self.timeout = 5
self.testUrl = "http://www.baidu.com/"
self.testStr = "030173"
def checkProxy