安装
pip install requests
设置代理
requests模块本身支持http代理。但默认安装下,要安装socks代理支持PySocks模块: pip install pysocks。代理示例
proxies={'http':'http://127.0.0.1:1080','https':'http://127.0.0.1:1080'} sess=requests.session() sess.get(url,proxies=proxy) proxies={'https':'socks5://127.0.0.1:1080','http':'socks5://127.0.0.1:1080'} req=requests.get(url,proxies=proxies)
requests 代理官方文档 https://2.python-requests.org/en/master/user/advanced/#socks