Skip to content

Commit

Permalink
增加fq代理的配置,配置后请调用代理访问wallproxy
Browse files Browse the repository at this point in the history
  • Loading branch information
highroom committed May 14, 2018
1 parent b4411bc commit f9a8bf5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ freeProxyWallThird = 1
; API接口配置 http://127.0.0.1:5010
ip = 0.0.0.0
port = 5010

[WallProxy]
; fq代理配置
; proxy = 127.0.0.1:1080
44 changes: 41 additions & 3 deletions ProxyGetter/getFreeProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
import re
import sys
import requests
import os

try:
from configparser import ConfigParser # py3
except:
from ConfigParser import ConfigParser # py2

try:
from importlib import reload # py3 实际不会实用,只是为了不显示语法错误
Expand Down Expand Up @@ -46,6 +52,15 @@ class GetFreeProxy(object):
"""
proxy getter
"""
pwd = os.path.split(os.path.realpath(__file__))[0]
config_path = os.path.join(os.path.split(pwd)[0], 'Config.ini')
config_file = ConfigParser()
config_file.read(config_path)
if config_file.has_option('WallProxy', 'proxy'):
WallProxy = config_file.get('WallProxy', 'proxy')
wall_proxies = {"http": "http://{}".format(WallProxy), "https": "https://{}".format(WallProxy)}
else:
wall_proxies = None

def __init__(self):
pass
Expand Down Expand Up @@ -257,10 +272,17 @@ def freeProxyWallFirst():
墙外网站 cn-proxy
:return:
"""
kwargs = {}
if GetFreeProxy.wall_proxies:
kwargs['proxies'] = GetFreeProxy.wall_proxies
else:
return

urls = ['http://cn-proxy.com/', 'http://cn-proxy.com/archives/218']
request = WebRequest()
for url in urls:
r = request.get(url)
kwargs['url'] = url
r = request.get(**kwargs)
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)
Expand All @@ -271,21 +293,35 @@ def freeProxyWallSecond():
https://proxy-list.org/english/index.php
:return:
"""
kwargs = {}
if GetFreeProxy.wall_proxies:
kwargs['proxies'] = GetFreeProxy.wall_proxies
else:
return
urls = ['https://proxy-list.org/english/index.php?p=%s' % n for n in range(1, 10)]
request = WebRequest()
import base64
for url in urls:
r = request.get(url)
kwargs['url'] = url
r = request.get(**kwargs)
proxies = re.findall(r"Proxy\('(.*?)'\)", r.text)
for proxy in proxies:
yield base64.b64decode(proxy).decode()

@staticmethod
def freeProxyWallThird():

kwargs = {}
if GetFreeProxy.wall_proxies:
kwargs['proxies'] = GetFreeProxy.wall_proxies
else:
return

urls = ['https://list.proxylistplus.com/Fresh-HTTP-Proxy-List-1']
request = WebRequest()
for url in urls:
r = request.get(url)
kwargs['url'] = url
r = request.get(**kwargs)
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)
Expand Down Expand Up @@ -319,3 +355,5 @@ def freeProxyWallThird():
# test_batch(gg.freeProxyWallSecond())

# test_batch(gg.freeProxyWallThird())
for e in gg.freeProxyWallThird():
print(e)
2 changes: 1 addition & 1 deletion Util/WebRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get(self, url, header=None, retry_time=5, timeout=30,
headers.update(header)
while True:
try:
html = requests.get(url, headers=headers, timeout=timeout)
html = requests.get(url, headers=headers, timeout=timeout, **kwargs)
if any(f in html.content for f in retry_flag):
raise Exception
return html
Expand Down

0 comments on commit f9a8bf5

Please sign in to comment.