我正在试着写一个程序,它将检查哪些代理是活动的。 当我的脚本尝试连接到非活动代理时,它甚至需要大约30秒。当我检查数千个代理的列表时,脚本的工作时间会增加几个小时。你知道吗
如果响应时间超过5秒,是否可能中断此功能?你知道吗
def get(url, proxy):
proxies = {
'http': 'http://'+proxy,
'https': 'https://'+proxy
}
s = requests.Session()
s.headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
s.proxies = proxies
r = s.get(url)
return [r.status_code, r.reason, r.text]
with open('proxy.txt') as ips:
for ip in ips:
ip = ip.split('\n', 1)[0]
try:
get(url, ip)
with open('working.txt', 'a') as the_file:
the_file.write(ip+'\n')
except:
print("error")
谢谢你。你知道吗
处理凌乱的HTML是凌乱的。使用HTML cleaner实用程序,例如HtmlCleaner来完成这项工作
我假设特殊字符不是字母和数字
输出:
相关问题 更多 >
编程相关推荐