网络编程
位置:首页>> 网络编程>> Python编程>> python requests使用socks5的例子

python requests使用socks5的例子

作者:WarmSword  发布时间:2023-09-14 07:06:45 

标签:python,requests,socks5

网络爬虫由于一个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。

来源:https://blog.csdn.net/junbujianwpl/article/details/79411472

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com