代理文本proxychains.txt格式
1 118.121.8.9 1080 SOCKS5
2 192.99.3.101 1080 SOCKS5
3 116.228.3.82 80 SOCKS5
4 45.56.108.26 16674 SOCKS5
----------------------------------------------------
# -*- coding:utf-8 -*-
import time
import requests
'''''
代理IP地址
'''
def getProxyIp():
proxy = []
inFile = open('proxychains.txt','r')
for line in inFile.readlines():
line = line.strip('\n')
IP= line.split("\t")
ip_temp = IP[0]+":"+IP[1]+":"+IP[2]
proxy.append(ip_temp)
return proxy
'''''
验证代理IP地址是否可用
'''
def validateIp(proxy):
url = "https://www.facebook.com"
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) '
'AppleWebKit/537.36 (KHTML,like Gecko) '
'Chrome/56.0.2924.87Safari/537.36'}
f = open("ip-socks5.txt","wb")
for i in range(0,len(proxy)):
try:
ip =proxy[i].split(":")
print ip
proxies = {'http':'socks5://'+ip[1]+":"+ip[2],'https':'socks5://'+ip[1]+":"+ip[2],}
url = 'https://www.facebook.com'
response = requests.get(url,proxies=proxies,timeout=5)
print(response.content)
f.write(ip+'\t') #proxy[i]
print ("successful")
time.sleep(2)
except Exception as e:
print("failed") # continue
f.close()
if __name__ == '__main__':
print "Running tests..."
proxy=getProxyIp()
validateIp(proxy)
领取专属 10元无门槛券
私享最新 技术干货