-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxyspy.py
61 lines (58 loc) · 1.71 KB
/
proxyspy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
"""
@author: yinti
email:[email protected]
"""
import re
import ssl
import urllib.request
import os
import zlib
import chardet
import time
from validateIP import validateIP
ssl._create_default_https_context = ssl._create_unverified_context
headers={"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE"}
def get(url):
url=urllib.request.Request(url=url,headers=headers)
h=urllib.request.urlopen(url)
html=h.read()
html = zlib.decompress(html, 16+zlib.MAX_WBITS)
#print(chardet.detect(html))
html=html.decode('utf-8')
return html
def findurl(html):
regx=re.compile('(href="(http|https).*?")',re.I)
h=regx.findall(html)
s=[]
for path,seq in h:
s.append(path)
return s
def findproxy(url):
pattip=re.compile('(<td data-title="IP">(\d|\.)*)',re.I)
pattport=re.compile('<td data-title="PORT">(\d{1,6})',re.I)
html=get(url)
ip=pattip.findall(html)
port=pattport.findall(html)
f=[]
s=[]
if len(ip)==len(port):
f1=open(r'E:\source code\python\spy\data\ippool\proxyip2.txt','at')
for n in range(len(ip)):
f.append(ip[n][0][20:]+":"+port[n])
if validateIP(ip[n][0][20:],port[n])==True:
s.append(ip[n][0][20:]+":"+port[n]+'\n')
print(f)
print(s)
f1.writelines(s)
f1.close()
#return s
else:
print('false')
for i in range(1,21):
try:
url='https://www.kuaidaili.com/free/intr/{}/'.format(i)
findproxy(url)
time.sleep(2)
except Exception:
continue