1 Star 0 Fork 1

endless/proxy_pool

forked from Admin/proxy_pool 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
proxy_helper.py 624 Bytes
一键复制 编辑 原始数据 按行查看 历史
xiaoou 提交于 2024-01-06 11:44 +08:00 . first summit
import requests
def get_proxy():
return requests.get("http://127.0.0.1:5010/get/").json()
def delete_proxy(proxy):
requests.get("http://127.0.0.1:5010/delete/?proxy={}".format(proxy))
# your spider code
def getHtml():
# ....
retry_count = 5
proxy = get_proxy().get("proxy")
while retry_count > 0:
try:
html = requests.get('http://www.example.com', proxies={"http": "http://{}".format(proxy)})
# 使用代理访问
return html
except Exception:
retry_count -= 1
# 删除代理池中代理
delete_proxy(proxy)
return None
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/endlesshh/proxy_pool.git
git@gitee.com:endlesshh/proxy_pool.git
endlesshh
proxy_pool
proxy_pool
master

搜索帮助