|
|
@@ -1,31 +1,24 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
-# !/usr/bin/env python
|
|
|
"""
|
|
|
-------------------------------------------------
|
|
|
- File Name: GetFreeProxy.py
|
|
|
- Description : 抓取免费代理
|
|
|
- Author : JHao
|
|
|
+ File Name: proxyFetcher
|
|
|
+ Description :
|
|
|
+ Author : JHao
|
|
|
date: 2016/11/25
|
|
|
-------------------------------------------------
|
|
|
Change Activity:
|
|
|
- 2016/11/25:
|
|
|
+ 2016/11/25: proxyFetcher
|
|
|
-------------------------------------------------
|
|
|
"""
|
|
|
+__author__ = 'JHao'
|
|
|
+
|
|
|
import re
|
|
|
-import sys
|
|
|
-import requests
|
|
|
from time import sleep
|
|
|
|
|
|
-sys.path.append('..')
|
|
|
-
|
|
|
-from Util.WebRequest import WebRequest
|
|
|
-from Util.utilFunction import getHtmlTree
|
|
|
+from util.webRequest import WebRequest
|
|
|
|
|
|
-# for debug to disable insecureWarning
|
|
|
-requests.packages.urllib3.disable_warnings()
|
|
|
|
|
|
-
|
|
|
-class GetFreeProxy(object):
|
|
|
+class ProxyFetcher(object):
|
|
|
"""
|
|
|
proxy getter
|
|
|
"""
|
|
|
@@ -44,7 +37,7 @@ class GetFreeProxy(object):
|
|
|
]
|
|
|
key = 'ABCDEFGHIZ'
|
|
|
for url in url_list:
|
|
|
- html_tree = getHtmlTree(url)
|
|
|
+ html_tree = WebRequest().get(url).tree
|
|
|
ul_list = html_tree.xpath('//ul[@class="l2"]')
|
|
|
for ul in ul_list:
|
|
|
try:
|
|
|
@@ -121,7 +114,7 @@ class GetFreeProxy(object):
|
|
|
for each_url in url_list:
|
|
|
for i in range(1, page_count + 1):
|
|
|
page_url = each_url + str(i)
|
|
|
- tree = getHtmlTree(page_url)
|
|
|
+ tree = WebRequest().get(page_url).tree
|
|
|
proxy_list = tree.xpath('.//table[@id="ip_list"]//tr[position()>1]')
|
|
|
for proxy in proxy_list:
|
|
|
try:
|
|
|
@@ -136,7 +129,7 @@ class GetFreeProxy(object):
|
|
|
:return:
|
|
|
"""
|
|
|
url = "http://www.goubanjia.com/"
|
|
|
- tree = getHtmlTree(url)
|
|
|
+ tree = WebRequest().get(url).tree
|
|
|
proxy_list = tree.xpath('//td[@class="ip"]')
|
|
|
# 此网站有隐藏的数字干扰,或抓取到多余的数字或.符号
|
|
|
# 需要过滤掉<p style="display:none;">的内容
|
|
|
@@ -176,7 +169,7 @@ class GetFreeProxy(object):
|
|
|
'https://www.kuaidaili.com/free/intr/'
|
|
|
]
|
|
|
for url in url_list:
|
|
|
- tree = getHtmlTree(url)
|
|
|
+ tree = WebRequest().get(url).tree
|
|
|
proxy_list = tree.xpath('.//table//tr')
|
|
|
sleep(1) # 必须sleep 不然第二条请求不到数据
|
|
|
for tr in proxy_list[1:]:
|
|
|
@@ -190,7 +183,7 @@ class GetFreeProxy(object):
|
|
|
"""
|
|
|
urls = ['https://proxy.coderbusy.com/']
|
|
|
for url in urls:
|
|
|
- tree = getHtmlTree(url)
|
|
|
+ tree = WebRequest().get(url).tree
|
|
|
proxy_list = tree.xpath('.//table//tr')
|
|
|
for tr in proxy_list[1:]:
|
|
|
yield ':'.join(tr.xpath('./td/text()')[0:2])
|
|
|
@@ -203,9 +196,8 @@ class GetFreeProxy(object):
|
|
|
"""
|
|
|
urls = ['http://www.ip3366.net/free/?stype=1',
|
|
|
"http://www.ip3366.net/free/?stype=2"]
|
|
|
- request = WebRequest()
|
|
|
for url in urls:
|
|
|
- r = request.get(url, timeout=10)
|
|
|
+ r = WebRequest().get(url, timeout=10)
|
|
|
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)
|
|
|
@@ -222,9 +214,8 @@ class GetFreeProxy(object):
|
|
|
'http://www.iphai.com/free/wg',
|
|
|
'http://www.iphai.com/free/wp'
|
|
|
]
|
|
|
- request = WebRequest()
|
|
|
for url in urls:
|
|
|
- r = request.get(url, timeout=10)
|
|
|
+ r = WebRequest().get(url, timeout=10)
|
|
|
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:
|
|
|
@@ -239,7 +230,7 @@ class GetFreeProxy(object):
|
|
|
"""
|
|
|
for i in range(1, page_count + 1):
|
|
|
url = 'http://ip.jiangxianli.com/?country=中国&?page={}'.format(i)
|
|
|
- html_tree = getHtmlTree(url)
|
|
|
+ html_tree = WebRequest().get(url).tree
|
|
|
for index, tr in enumerate(html_tree.xpath("//table//tr")):
|
|
|
if index == 0:
|
|
|
continue
|
|
|
@@ -293,10 +284,9 @@ class GetFreeProxy(object):
|
|
|
:return:
|
|
|
"""
|
|
|
base_url = 'http://www.qydaili.com/free/?action=china&page='
|
|
|
- request = WebRequest()
|
|
|
for page in range(1, max_page + 1):
|
|
|
url = base_url + str(page)
|
|
|
- r = request.get(url, timeout=10)
|
|
|
+ r = WebRequest().get(url, timeout=10)
|
|
|
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)
|
|
|
@@ -312,10 +302,9 @@ class GetFreeProxy(object):
|
|
|
:return:
|
|
|
"""
|
|
|
base_url = 'http://www.89ip.cn/index_{}.html'
|
|
|
- request = WebRequest()
|
|
|
for page in range(1, max_page + 1):
|
|
|
url = base_url.format(page)
|
|
|
- r = request.get(url, timeout=10)
|
|
|
+ r = WebRequest().get(url, timeout=10)
|
|
|
proxies = re.findall(
|
|
|
r'<td.*?>[\s\S]*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})[\s\S]*?</td>[\s\S]*?<td.*?>[\s\S]*?(\d+)[\s\S]*?</td>',
|
|
|
r.text)
|
|
|
@@ -328,28 +317,8 @@ class GetFreeProxy(object):
|
|
|
"http://www.xiladaili.com/gaoni/",
|
|
|
"http://www.xiladaili.com/http/",
|
|
|
"http://www.xiladaili.com/https/"]
|
|
|
- request = WebRequest()
|
|
|
for url in urls:
|
|
|
- r = request.get(url, timeout=10)
|
|
|
+ r = WebRequest().get(url, timeout=10)
|
|
|
ips = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}", r.text)
|
|
|
for ip in ips:
|
|
|
yield ip.strip()
|
|
|
-
|
|
|
-
|
|
|
-if __name__ == '__main__':
|
|
|
- from CheckProxy import CheckProxy
|
|
|
-
|
|
|
- # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy01)
|
|
|
- # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy02)
|
|
|
- # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy03)
|
|
|
- # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy04)
|
|
|
- # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy05)
|
|
|
- # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy06)
|
|
|
- # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy07)
|
|
|
- # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy08)
|
|
|
- # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy09)
|
|
|
- # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy13)
|
|
|
- # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy14)
|
|
|
- # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy15)
|
|
|
-
|
|
|
- CheckProxy.checkAllGetProxyFunc()
|