python requests使用socks5的例子
时间:2021-07-06 10:09:18|栏目:Python代码|点击: 次
网络爬虫由于一个ip频繁访问同一网站,容易返回456或者被长时间封禁。
特别的本机有socks5客户端的设置如下,前提是已经安装了socks5的客户端软件,并且启动起来在固定端口为本机提供服务。
使用前先更新requests版本为支持socks的版本。
pip install -U requests[socks]
import requests
my_proxies={"http":"http://127.0.0.1:1080","https":"https://127.0.0.1:1080"}
resp=requests.get("http://www.some.com",proxies=my_proxies,timeout=5)
print(resp.text)
注意其中的地址协议写的是http和https。
栏 目:Python代码
下一篇:Python八大常见排序算法定义、实现及时间消耗效率分析
本文标题:python requests使用socks5的例子
本文地址:http://www.codeinn.net/misctech/153416.html






