python - Urllib 提供假代理
问题描述
我用这个脚本测试我的代理,它提供了很多工作,但是当我用另一个代理检查器测试“工作”代理时,只有很少量的工作。
这是检查代理是否有效的部分:
def process(self, task):
global alive
global dead
global tested
proxy = task
log_msg = str("Trying HTTP proxy%21s " % proxy)
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(cj),
urllib.request.HTTPRedirectHandler(),
urllib.request.ProxyHandler({'http': proxy})
)
try:
t1 = time.time()
response = opener.open(test_url, timeout=timeout_value).read()
tested += 1
t2 = time.time()
except Exception as e:
log_msg += "%s " % fail_msg
print(Fore.LIGHTRED_EX + log_msg)
dead += 1
tested += 1
return None
log_msg += ok_msg + "Response time: %d" % (int((t2-t1)*1000))
print(Fore.LIGHTGREEN_EX + log_msg)
text_file = open(out_filename, "a")
text_file.write(proxy + "\r\n")
text_file.close()
alive += 1
解决方案
推荐阅读
- javascript - 如何检索对象数组的某些属性并将其放入新的对象数组中?
- c# - 如何模拟 IMessageReceiver?
- tensorflow - 出于贡献目的从源代码更快地构建 tensorflow
- javascript - 将手风琴移到打开的手风琴旁边
- docker - 禁用清理使用 --rm 运行的容器
- ios - SwiftUI - 如何在视图基础上设置画外音语言?
- cakephp - 如何在 CakePHP 3 中找到 SecurityComponent 配置选项?
- sql-server - 尝试连接到 Microsoft SQL Server 19 时出现“Unicode 错误”
- javascript - 在提交时禁用单击按钮
- python - 从数据库 MySQL 获取印地语文本,尝试了所有解决方案但失败了