前言
如何在 requests 模块中使用代理发送请求
requests 使用代理
在requests模块中使用代理示例
# 作者-上海悠悠 微信/QQ交流:283340479# blog地址 /yoyoketang/url = ""proxies = {"http": "http://代理ip:端口","https": "https://代理ip:端口"}r = requests.get(url, proxies=proxies)print(r.text)
使用需要账号和密码的代理
import requestsurl = ""proxies = {"http": "http://username:password@ip:端口号","https": "https://username:password@ip:端口号"}r = requests.get(url, proxies=proxies)print(r.text)
session 会话使用代理
在session会话中可以设置全局管理代理
# 作者-上海悠悠 微信/QQ交流:283340479# blog地址 /yoyoketang/import requestsurl = ""s = requests.Session()s.proxies = {"http": "http://代理ip:端口","https": "https://代理ip:端口"}r = s.get(url)print(r.text)