Skip to content

Commit 5b77e39

Browse files
committed
Socks5 Support added. Added new proxy site as datasource.
Using Selenium + PhantomJS instead.
1 parent ec8131f commit 5b77e39

File tree

4 files changed

+64
-17
lines changed

4 files changed

+64
-17
lines changed

async_proxy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async def handle_client(reader,writer):
3232
use_proxy = True
3333
if use_proxy:
3434
try:
35-
if proxy[2]=='socks':
35+
if proxy[2]=='SOCKS5':
3636
socks5_addr = aiosocks.Socks5Addr(proxy[0],proxy[1])
3737
remote_reader, remote_writer = await aiosocks.open_connection(
3838
proxy=socks5_addr, dst=[dest[0],dest[1]], remote_resolve=True)

components/proxy_fetcher.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
import yaml
44
from bs4 import BeautifulSoup
55
from profile.proxy_rules import get_data_on_profile
6+
from selenium import webdriver
7+
68

79
class ProxyFetcher(object):
810
instance = None
911
proxys=None
12+
driver = webdriver.PhantomJS()
13+
1014
def __init__(self,urls,candidate_num=5):
1115
self.urls=urls
1216
self.candidate=candidate_num
@@ -32,20 +36,28 @@ def yaml_loader(file):
3236
def proxy_fetcher(self,url):
3337
resp=requests.get(url)
3438
if resp.status_code<300:
35-
return resp.content
39+
self.driver.get(url)
40+
return self.driver
3641
else:
3742
raise Exception("ERROR : The Proxy Website is DOWN.")
3843

3944
def proxy_parser(self):
45+
4046
try:
4147
self.proxys=[]
4248
for server in self.urls:
43-
data=self.proxy_fetcher(server['url'])
44-
soup = BeautifulSoup(data,"html5lib")
49+
# data=self.proxy_fetcher(server['url'])
50+
# soup = BeautifulSoup(data,"html5lib")
51+
# try:
52+
# self.proxys.extend(get_data_on_profile(server['name'],soup,self.candidate))
53+
# except Exception as e:
54+
# pass
55+
driver = self.proxy_fetcher(server['url'])
4556
try:
46-
self.proxys.extend(get_data_on_profile(server['name'],soup,self.candidate))
57+
self.proxys.extend(get_data_on_profile(server['name'],driver,self.candidate))
4758
except Exception as e:
4859
pass
60+
4961
print("Got Proxies:")
5062
print((self.proxys))
5163
except Exception as e:

profile/proxy_rules.py

+45-11
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,63 @@
11
# Define proxy Profile here.
22

3-
def get_data_on_profile(profile,soup,number):
3+
# def get_data_on_profile(profile,soup,number):
4+
# # Define profile here
5+
# # Return a List with ip and port, example: [["127.0.0.1","1080","http"]]
6+
# result=[]
7+
#
8+
# if profile=='cnproxy':
9+
# proxy_list = soup.select("tbody tr")
10+
# for i in range(0, number):
11+
# try:
12+
# result.append([proxy_list[i].select("td:nth-of-type(1)")[0].text.strip("-").strip(),
13+
# proxy_list[i].select("td:nth-of-type(2)")[0].text.strip(), 'http'])
14+
# except Exception as e:
15+
# pass
16+
# elif profile=='proxynova':
17+
# proxy_list = soup.select("tbody tr")
18+
# for i in range(0, number):
19+
# try:
20+
# result.append( [proxy_list[i].select("td:nth-of-type(1)")[0].abbr.attrs['title'].strip(),
21+
# proxy_list[i].select("td:nth-of-type(2)")[0].text.strip(),'http'])
22+
# except:
23+
# pass
24+
# elif profile=='spysone':
25+
#
26+
# proxy_list = soup.select("tr.spy1x,tr.spy1xx")
27+
# for i in range(0,number):
28+
# proxy_list[i].select("td:nth-of-type(1)")
29+
# print(soup)
30+
# return result
31+
32+
33+
def get_data_on_profile(profile,driver,number):
434
# Define profile here
535
# Return a List with ip and port, example: [["127.0.0.1","1080","http"]]
636
result=[]
737

838
if profile=='cnproxy':
9-
proxy_list = soup.select("tbody tr")
39+
proxy_list = driver.find_elements_by_css_selector("tbody tr")
1040
for i in range(0, number):
1141
try:
12-
result.append([proxy_list[i].select("td:nth-of-type(1)")[0].text.strip("-").strip(),
13-
proxy_list[i].select("td:nth-of-type(2)")[0].text.strip(), 'http'])
42+
result.append([proxy_list[i].find_elements_by_css_selector("td:nth-of-type(1)")[0].text.strip("-").strip(),
43+
proxy_list[i].find_elements_by_css_selector("td:nth-of-type(2)")[0].text.strip(), 'HTTP'])
1444
except Exception as e:
1545
pass
1646
elif profile=='proxynova':
17-
proxy_list = soup.select("tbody tr")
47+
proxy_list = driver.find_elements_by_css_selector("tbody tr")
1848
for i in range(0, number):
1949
try:
20-
result.append( [proxy_list[i].select("td:nth-of-type(1)")[0].abbr.attrs['title'].strip(),
21-
proxy_list[i].select("td:nth-of-type(2)")[0].text.strip(),'http'])
50+
result.append( [proxy_list[i].find_elements_by_css_selector("td:nth-of-type(1)")[0].text.strip(),
51+
proxy_list[i].find_elements_by_css_selector("td:nth-of-type(2)")[0].text.strip(),'HTTP'])
2252
except:
2353
pass
2454
elif profile=='spysone':
25-
proxy_list = soup.select("tr.spy1x,tr.spy1xx")
26-
for i in range(0,number):
27-
proxy_list[i].select("td:nth-of-type(1)")
28-
print(soup)
55+
56+
proxy_list = driver.find_elements_by_css_selector("tr.spy1x,tr.spy1xx")
57+
if len(proxy_list)<number+2:
58+
number = len(proxy_list)-2
59+
for i in range(2,number+2):
60+
proxy_info = proxy_list[i].text.strip().split(" ")
61+
result.append([proxy_info[1].split(":")[0],proxy_info[1].split(":")[1],proxy_info[2]])
62+
print(driver)
2963
return result

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ html5lib
66
dnslib
77
pysocks
88
requests[socks]
9-
aiosocks
9+
aiosocks
10+
selenium

0 commit comments

Comments
 (0)