注册
登录
 文档中心 产品介绍 开发指南 API接口 代码样例 使用帮助
Python3使用requests调用Socks5代理IP的代码样例
站大爷 官方 2024-01-19 2053 浏览

温馨提示:

1.  http/https网页均可适用

2.  运行环境要求:requests >= 2.10.0

3.  socks支持是requests的额外特性,需要安装才能使用: pip install requests[socks]

4.  注意当前授权模式,选择对应的proxies


import requests

# 用户名密码授权,username是实例ID,password是8位数字的实例密码

proxies = {
	"http": "socks5h://username:password@123.68.68.88:16888",
	"https": "socks5h://username:password@123.68.68.88:16888"
}

# 终端IP授权(需提前绑定使用者终端IP)
# proxies = {
#	"http": "socks5h://123.68.68.88:16888",
#	"https": "socks5h://123.68.68.88:16888"
# }

# 要访问的目标网页
target_url = "https://example.com"

# 使用代理IP发送请求
response = requests.get(target_url, proxies=proxies)

# 获取页面内容
if response.status_code == 200:
	print(response.text)


立即注册站大爷用户,免费试用全部产品
立即注册站大爷用户,免费试用全部产品