|
@@ -21,7 +21,7 @@ except:
|
|
|
reload(sys)
|
|
reload(sys)
|
|
|
sys.setdefaultencoding('utf-8')
|
|
sys.setdefaultencoding('utf-8')
|
|
|
|
|
|
|
|
-sys.path.append('../')
|
|
|
|
|
|
|
+sys.path.append('..')
|
|
|
|
|
|
|
|
from Util.utilFunction import robustCrawl, getHtmlTree
|
|
from Util.utilFunction import robustCrawl, getHtmlTree
|
|
|
from Util.WebRequest import WebRequest
|
|
from Util.WebRequest import WebRequest
|
|
@@ -30,18 +30,15 @@ from Util.WebRequest import WebRequest
|
|
|
requests.packages.urllib3.disable_warnings()
|
|
requests.packages.urllib3.disable_warnings()
|
|
|
|
|
|
|
|
"""
|
|
"""
|
|
|
-66ip.cn
|
|
|
|
|
-data5u.com
|
|
|
|
|
-ip181.com
|
|
|
|
|
-xicidaili.com
|
|
|
|
|
-goubanjia.com
|
|
|
|
|
-xdaili.cn
|
|
|
|
|
-kuaidaili.com
|
|
|
|
|
-cn-proxy.com
|
|
|
|
|
-www.mimiip.com
|
|
|
|
|
-proxy-list.org
|
|
|
|
|
-cz88.net
|
|
|
|
|
-ip181.com
|
|
|
|
|
|
|
+ 66ip.cn
|
|
|
|
|
+ data5u.com
|
|
|
|
|
+ xicidaili.com
|
|
|
|
|
+ goubanjia.com
|
|
|
|
|
+ xdaili.cn
|
|
|
|
|
+ kuaidaili.com
|
|
|
|
|
+ cn-proxy.com
|
|
|
|
|
+ proxy-list.org
|
|
|
|
|
+ www.mimiip.com to do
|
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
@@ -56,14 +53,16 @@ class GetFreeProxy(object):
|
|
|
@staticmethod
|
|
@staticmethod
|
|
|
def freeProxyFirst(page=10):
|
|
def freeProxyFirst(page=10):
|
|
|
"""
|
|
"""
|
|
|
- 抓取无忧代理 http://www.data5u.com/
|
|
|
|
|
|
|
+ 无忧代理 http://www.data5u.com/
|
|
|
|
|
+ 几乎没有能用的
|
|
|
:param page: 页数
|
|
:param page: 页数
|
|
|
:return:
|
|
:return:
|
|
|
"""
|
|
"""
|
|
|
- url_list = ['http://www.data5u.com/',
|
|
|
|
|
- 'http://www.data5u.com/free/',
|
|
|
|
|
- 'http://www.data5u.com/free/gngn/index.shtml',
|
|
|
|
|
- 'http://www.data5u.com/free/gnpt/index.shtml']
|
|
|
|
|
|
|
+ url_list = [
|
|
|
|
|
+ 'http://www.data5u.com/',
|
|
|
|
|
+ 'http://www.data5u.com/free/gngn/index.shtml',
|
|
|
|
|
+ 'http://www.data5u.com/free/gnpt/index.shtml'
|
|
|
|
|
+ ]
|
|
|
for url in url_list:
|
|
for url in url_list:
|
|
|
html_tree = getHtmlTree(url)
|
|
html_tree = getHtmlTree(url)
|
|
|
ul_list = html_tree.xpath('//ul[@class="l2"]')
|
|
ul_list = html_tree.xpath('//ul[@class="l2"]')
|
|
@@ -71,26 +70,32 @@ class GetFreeProxy(object):
|
|
|
try:
|
|
try:
|
|
|
yield ':'.join(ul.xpath('.//li/text()')[0:2])
|
|
yield ':'.join(ul.xpath('.//li/text()')[0:2])
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- pass
|
|
|
|
|
|
|
+ print(e)
|
|
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
|
- def freeProxySecond(proxy_number=100):
|
|
|
|
|
|
|
+ def freeProxySecond(area=33, page=1):
|
|
|
"""
|
|
"""
|
|
|
- 抓取代理66 http://www.66ip.cn/
|
|
|
|
|
- :param proxy_number: 代理数量
|
|
|
|
|
|
|
+ 代理66 http://www.66ip.cn/
|
|
|
|
|
+ :param area: 抓取代理页数,page=1北京代理页,page=2上海代理页......
|
|
|
|
|
+ :param page: 翻页
|
|
|
:return:
|
|
:return:
|
|
|
"""
|
|
"""
|
|
|
- url = "http://www.66ip.cn/mo.php?sxb=&tqsl={}&port=&export=&ktip=&sxa=&submit=%CC%E1++%C8%A1&textarea=".format(
|
|
|
|
|
- proxy_number)
|
|
|
|
|
- request = WebRequest()
|
|
|
|
|
- html = request.get(url).text
|
|
|
|
|
- for proxy in re.findall(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}', html):
|
|
|
|
|
- yield proxy
|
|
|
|
|
|
|
+ area = 33 if area > 33 else area
|
|
|
|
|
+ for area_index in range(1, area + 1):
|
|
|
|
|
+ for i in range(1, page + 1):
|
|
|
|
|
+ url = "http://www.66ip.cn/areaindex_{}/{}.html".format(area_index, i)
|
|
|
|
|
+ html_tree = getHtmlTree(url)
|
|
|
|
|
+ tr_list = html_tree.xpath("//*[@id='footer']/div/table/tr[position()>1]")
|
|
|
|
|
+ if len(tr_list) == 0:
|
|
|
|
|
+ continue
|
|
|
|
|
+ for tr in tr_list:
|
|
|
|
|
+ yield tr.xpath("./td[1]/text()")[0] + ":" + tr.xpath("./td[2]/text()")[0]
|
|
|
|
|
+ break
|
|
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
|
def freeProxyThird(days=1):
|
|
def freeProxyThird(days=1):
|
|
|
"""
|
|
"""
|
|
|
- 抓取ip181 http://www.ip181.com/
|
|
|
|
|
|
|
+ ip181 http://www.ip181.com/ 不能用了
|
|
|
:param days:
|
|
:param days:
|
|
|
:return:
|
|
:return:
|
|
|
"""
|
|
"""
|
|
@@ -104,55 +109,55 @@ class GetFreeProxy(object):
|
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
|
- def freeProxyFourth():
|
|
|
|
|
|
|
+ def freeProxyFourth(page_count=2):
|
|
|
"""
|
|
"""
|
|
|
- 抓取西刺代理 http://api.xicidaili.com/free2016.txt
|
|
|
|
|
|
|
+ 西刺代理 http://www.xicidaili.com
|
|
|
:return:
|
|
:return:
|
|
|
"""
|
|
"""
|
|
|
- url_list = ['http://www.xicidaili.com/nn', # 高匿
|
|
|
|
|
- 'http://www.xicidaili.com/nt', # 透明
|
|
|
|
|
- ]
|
|
|
|
|
|
|
+ url_list = [
|
|
|
|
|
+ 'http://www.xicidaili.com/nn/', # 高匿
|
|
|
|
|
+ 'http://www.xicidaili.com/nt/', # 透明
|
|
|
|
|
+ ]
|
|
|
for each_url in url_list:
|
|
for each_url in url_list:
|
|
|
- tree = getHtmlTree(each_url)
|
|
|
|
|
- proxy_list = tree.xpath('.//table[@id="ip_list"]//tr')
|
|
|
|
|
- for proxy in proxy_list:
|
|
|
|
|
- try:
|
|
|
|
|
- yield ':'.join(proxy.xpath('./td/text()')[0:2])
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- pass
|
|
|
|
|
|
|
+ for i in range(1, page_count + 1):
|
|
|
|
|
+ page_url = each_url + str(i)
|
|
|
|
|
+ tree = getHtmlTree(page_url)
|
|
|
|
|
+ proxy_list = tree.xpath('.//table[@id="ip_list"]//tr[position()>1]')
|
|
|
|
|
+ for proxy in proxy_list:
|
|
|
|
|
+ try:
|
|
|
|
|
+ yield ':'.join(proxy.xpath('./td/text()')[0:2])
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ pass
|
|
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
|
def freeProxyFifth():
|
|
def freeProxyFifth():
|
|
|
"""
|
|
"""
|
|
|
- 抓取guobanjia http://www.goubanjia.com/free/gngn/index.shtml
|
|
|
|
|
|
|
+ guobanjia http://www.goubanjia.com/
|
|
|
:return:
|
|
:return:
|
|
|
"""
|
|
"""
|
|
|
- url = "http://www.goubanjia.com/free/gngn/index{page}.shtml"
|
|
|
|
|
- for page in range(1, 10):
|
|
|
|
|
- page_url = url.format(page=page)
|
|
|
|
|
- tree = getHtmlTree(page_url)
|
|
|
|
|
- proxy_list = tree.xpath('//td[@class="ip"]')
|
|
|
|
|
- # 此网站有隐藏的数字干扰,或抓取到多余的数字或.符号
|
|
|
|
|
- # 需要过滤掉<p style="display:none;">的内容
|
|
|
|
|
- xpath_str = """.//*[not(contains(@style, 'display: none'))
|
|
|
|
|
- and not(contains(@style, 'display:none'))
|
|
|
|
|
- and not(contains(@class, 'port'))
|
|
|
|
|
- ]/text()
|
|
|
|
|
- """
|
|
|
|
|
- for each_proxy in proxy_list:
|
|
|
|
|
- try:
|
|
|
|
|
- # :符号裸放在td下,其他放在div span p中,先分割找出ip,再找port
|
|
|
|
|
- ip_addr = ''.join(each_proxy.xpath(xpath_str))
|
|
|
|
|
- port = each_proxy.xpath(
|
|
|
|
|
- ".//span[contains(@class, 'port')]/text()")[0]
|
|
|
|
|
- yield '{}:{}'.format(ip_addr, port)
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- pass
|
|
|
|
|
|
|
+ url = "http://www.goubanjia.com/"
|
|
|
|
|
+ tree = getHtmlTree(url)
|
|
|
|
|
+ proxy_list = tree.xpath('//td[@class="ip"]')
|
|
|
|
|
+ # 此网站有隐藏的数字干扰,或抓取到多余的数字或.符号
|
|
|
|
|
+ # 需要过滤掉<p style="display:none;">的内容
|
|
|
|
|
+ xpath_str = """.//*[not(contains(@style, 'display: none'))
|
|
|
|
|
+ and not(contains(@style, 'display:none'))
|
|
|
|
|
+ and not(contains(@class, 'port'))
|
|
|
|
|
+ ]/text()
|
|
|
|
|
+ """
|
|
|
|
|
+ for each_proxy in proxy_list:
|
|
|
|
|
+ try:
|
|
|
|
|
+ # :符号裸放在td下,其他放在div span p中,先分割找出ip,再找port
|
|
|
|
|
+ ip_addr = ''.join(each_proxy.xpath(xpath_str))
|
|
|
|
|
+ port = each_proxy.xpath(".//span[contains(@class, 'port')]/text()")[0]
|
|
|
|
|
+ yield '{}:{}'.format(ip_addr, port)
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ pass
|
|
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
|
def freeProxySixth():
|
|
def freeProxySixth():
|
|
|
"""
|
|
"""
|
|
|
- 抓取讯代理免费proxy http://www.xdaili.cn/ipagent/freeip/getFreeIps?page=1&rows=10
|
|
|
|
|
|
|
+ 讯代理 http://www.xdaili.cn/
|
|
|
:return:
|
|
:return:
|
|
|
"""
|
|
"""
|
|
|
url = 'http://www.xdaili.cn/ipagent/freeip/getFreeIps?page=1&rows=10'
|
|
url = 'http://www.xdaili.cn/ipagent/freeip/getFreeIps?page=1&rows=10'
|
|
@@ -167,15 +172,84 @@ class GetFreeProxy(object):
|
|
|
@staticmethod
|
|
@staticmethod
|
|
|
def freeProxySeventh():
|
|
def freeProxySeventh():
|
|
|
"""
|
|
"""
|
|
|
- 快代理免费https://www.kuaidaili.com/free/inha/1/
|
|
|
|
|
|
|
+ 快代理 https://www.kuaidaili.com
|
|
|
"""
|
|
"""
|
|
|
- url = 'https://www.kuaidaili.com/free/inha/{page}/'
|
|
|
|
|
- for page in range(1, 10):
|
|
|
|
|
- page_url = url.format(page=page)
|
|
|
|
|
- tree = getHtmlTree(page_url)
|
|
|
|
|
- proxy_list = tree.xpath('.//table//tr')
|
|
|
|
|
- for tr in proxy_list[1:]:
|
|
|
|
|
- yield ':'.join(tr.xpath('./td/text()')[0:2])
|
|
|
|
|
|
|
+ url_list = [
|
|
|
|
|
+ 'https://www.kuaidaili.com/free/inha/{page}/',
|
|
|
|
|
+ 'https://www.kuaidaili.com/free/intr/{page}/'
|
|
|
|
|
+ ]
|
|
|
|
|
+ for url in url_list:
|
|
|
|
|
+ for page in range(1, 5):
|
|
|
|
|
+ page_url = url.format(page=page)
|
|
|
|
|
+ tree = getHtmlTree(page_url)
|
|
|
|
|
+ proxy_list = tree.xpath('.//table//tr')
|
|
|
|
|
+ for tr in proxy_list[1:]:
|
|
|
|
|
+ yield ':'.join(tr.xpath('./td/text()')[0:2])
|
|
|
|
|
+
|
|
|
|
|
+ @staticmethod
|
|
|
|
|
+ def freeProxyEight():
|
|
|
|
|
+ """
|
|
|
|
|
+ 秘密代理 http://www.mimiip.com
|
|
|
|
|
+ """
|
|
|
|
|
+ url_gngao = ['http://www.mimiip.com/gngao/%s' % n for n in range(1, 10)] # 国内高匿
|
|
|
|
|
+ url_gnpu = ['http://www.mimiip.com/gnpu/%s' % n for n in range(1, 10)] # 国内普匿
|
|
|
|
|
+ url_gntou = ['http://www.mimiip.com/gntou/%s' % n for n in range(1, 10)] # 国内透明
|
|
|
|
|
+ url_list = url_gngao + url_gnpu + url_gntou
|
|
|
|
|
+
|
|
|
|
|
+ request = WebRequest()
|
|
|
|
|
+ for url in url_list:
|
|
|
|
|
+ r = request.get(url, use_proxy=True)
|
|
|
|
|
+ proxies = re.findall(r'<td>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})</td>[\w\W].*<td>(\d+)</td>', r.text)
|
|
|
|
|
+ for proxy in proxies:
|
|
|
|
|
+ yield ':'.join(proxy)
|
|
|
|
|
+
|
|
|
|
|
+ @staticmethod
|
|
|
|
|
+ def freeProxyNinth():
|
|
|
|
|
+ """
|
|
|
|
|
+ 码农代理 https://proxy.coderbusy.com/
|
|
|
|
|
+ :return:
|
|
|
|
|
+ """
|
|
|
|
|
+ urls = ['https://proxy.coderbusy.com/classical/country/cn.aspx?page=1']
|
|
|
|
|
+ request = WebRequest()
|
|
|
|
|
+ for url in urls:
|
|
|
|
|
+ r = request.get(url)
|
|
|
|
|
+ proxies = re.findall('data-ip="(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})".+?>(\d+)</td>', r.text)
|
|
|
|
|
+ for proxy in proxies:
|
|
|
|
|
+ yield ':'.join(proxy)
|
|
|
|
|
+
|
|
|
|
|
+ @staticmethod
|
|
|
|
|
+ def freeProxyTen():
|
|
|
|
|
+ """
|
|
|
|
|
+ 云代理 http://www.ip3366.net/free/
|
|
|
|
|
+ :return:
|
|
|
|
|
+ """
|
|
|
|
|
+ urls = ['http://www.ip3366.net/free/']
|
|
|
|
|
+ request = WebRequest()
|
|
|
|
|
+ for url in urls:
|
|
|
|
|
+ r = request.get(url)
|
|
|
|
|
+ proxies = re.findall(r'<td>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})</td>[\s\S]*?<td>(\d+)</td>', r.text)
|
|
|
|
|
+ for proxy in proxies:
|
|
|
|
|
+ yield ":".join(proxy)
|
|
|
|
|
+
|
|
|
|
|
+ @staticmethod
|
|
|
|
|
+ def freeProxyEleven():
|
|
|
|
|
+ """
|
|
|
|
|
+ IP海 http://www.iphai.com/free/ng
|
|
|
|
|
+ :return:
|
|
|
|
|
+ """
|
|
|
|
|
+ urls = [
|
|
|
|
|
+ 'http://www.iphai.com/free/ng',
|
|
|
|
|
+ 'http://www.iphai.com/free/np',
|
|
|
|
|
+ 'http://www.iphai.com/free/wg',
|
|
|
|
|
+ 'http://www.iphai.com/free/wp'
|
|
|
|
|
+ ]
|
|
|
|
|
+ request = WebRequest()
|
|
|
|
|
+ for url in urls:
|
|
|
|
|
+ r = request.get(url)
|
|
|
|
|
+ proxies = re.findall(r'<td>\s*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s*?</td>[\s\S]*?<td>\s*?(\d+)\s*?</td>',
|
|
|
|
|
+ r.text)
|
|
|
|
|
+ for proxy in proxies:
|
|
|
|
|
+ yield ":".join(proxy)
|
|
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
|
def freeProxyWallFirst():
|
|
def freeProxyWallFirst():
|
|
@@ -187,15 +261,17 @@ class GetFreeProxy(object):
|
|
|
request = WebRequest()
|
|
request = WebRequest()
|
|
|
for url in urls:
|
|
for url in urls:
|
|
|
r = request.get(url)
|
|
r = request.get(url)
|
|
|
- proxies = re.findall(
|
|
|
|
|
- r'<td>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})</td>[\w\W]<td>(\d+)</td>', r.text)
|
|
|
|
|
|
|
+ proxies = re.findall(r'<td>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})</td>[\w\W]<td>(\d+)</td>', r.text)
|
|
|
for proxy in proxies:
|
|
for proxy in proxies:
|
|
|
yield ':'.join(proxy)
|
|
yield ':'.join(proxy)
|
|
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
|
def freeProxyWallSecond():
|
|
def freeProxyWallSecond():
|
|
|
- urls = ['https://proxy-list.org/english/index.php?p=%s' %
|
|
|
|
|
- n for n in range(1, 10)]
|
|
|
|
|
|
|
+ """
|
|
|
|
|
+ https://proxy-list.org/english/index.php
|
|
|
|
|
+ :return:
|
|
|
|
|
+ """
|
|
|
|
|
+ urls = ['https://proxy-list.org/english/index.php?p=%s' % n for n in range(1, 10)]
|
|
|
request = WebRequest()
|
|
request = WebRequest()
|
|
|
import base64
|
|
import base64
|
|
|
for url in urls:
|
|
for url in urls:
|
|
@@ -204,34 +280,42 @@ class GetFreeProxy(object):
|
|
|
for proxy in proxies:
|
|
for proxy in proxies:
|
|
|
yield base64.b64decode(proxy).decode()
|
|
yield base64.b64decode(proxy).decode()
|
|
|
|
|
|
|
|
|
|
+ @staticmethod
|
|
|
|
|
+ def freeProxyWallThird():
|
|
|
|
|
+ urls = ['https://list.proxylistplus.com/Fresh-HTTP-Proxy-List-1']
|
|
|
|
|
+ request = WebRequest()
|
|
|
|
|
+ for url in urls:
|
|
|
|
|
+ r = request.get(url)
|
|
|
|
|
+ proxies = re.findall(r'<td>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})</td>[\s\S]*?<td>(\d+)</td>', r.text)
|
|
|
|
|
+ for proxy in proxies:
|
|
|
|
|
+ yield ':'.join(proxy)
|
|
|
|
|
+
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
|
gg = GetFreeProxy()
|
|
gg = GetFreeProxy()
|
|
|
- # for e in gg.freeProxyFirst():
|
|
|
|
|
- # print(e)
|
|
|
|
|
- #
|
|
|
|
|
- # for e in gg.freeProxySecond():
|
|
|
|
|
- # print(e)
|
|
|
|
|
- #
|
|
|
|
|
- # for e in gg.freeProxyThird():
|
|
|
|
|
- # print(e)
|
|
|
|
|
- #
|
|
|
|
|
- # for e in gg.freeProxyFourth():
|
|
|
|
|
- # print(e)
|
|
|
|
|
- #
|
|
|
|
|
- # for e in gg.freeProxyFifth():
|
|
|
|
|
- # print(e)
|
|
|
|
|
- #
|
|
|
|
|
- # for e in gg.freeProxySixth():
|
|
|
|
|
- # print(e)
|
|
|
|
|
- #
|
|
|
|
|
- # for e in gg.freeProxySeventh():
|
|
|
|
|
- # print(e)
|
|
|
|
|
-
|
|
|
|
|
- #
|
|
|
|
|
- #
|
|
|
|
|
- # for e in gg.freeProxyWallFirst():
|
|
|
|
|
- # print(e)
|
|
|
|
|
- #
|
|
|
|
|
- for e in gg.freeProxyWallSecond():
|
|
|
|
|
- print(e)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ # test_batch(gg.freeProxyFirst())
|
|
|
|
|
+
|
|
|
|
|
+ # test_batch(gg.freeProxySecond())
|
|
|
|
|
+
|
|
|
|
|
+ # test_batch(gg.freeProxyFourth())
|
|
|
|
|
+
|
|
|
|
|
+ # test_batch(gg.freeProxyFifth())
|
|
|
|
|
+
|
|
|
|
|
+ # test_batch(gg.freeProxySixth())
|
|
|
|
|
+
|
|
|
|
|
+ # test_batch(gg.freeProxySeventh())
|
|
|
|
|
+
|
|
|
|
|
+ # test_batch(gg.freeProxyEight())
|
|
|
|
|
+
|
|
|
|
|
+ # test_batch(gg.freeProxyNinth())
|
|
|
|
|
+
|
|
|
|
|
+ # test_batch(gg.freeProxyTen())
|
|
|
|
|
+
|
|
|
|
|
+ # test_batch(gg.freeProxyEleven())
|
|
|
|
|
+
|
|
|
|
|
+ # test_batch(gg.freeProxyWallFirst())
|
|
|
|
|
+
|
|
|
|
|
+ # test_batch(gg.freeProxyWallSecond())
|
|
|
|
|
+
|
|
|
|
|
+ # test_batch(gg.freeProxyWallThird())
|