一、代码示例
#, - *安康;编码:utf-8 - * - import 请求 header =, { ,,,& # 39;用户代理# 39;:,& # 39;Mozilla/5.0, (Windows NT 6.1;, Win64;, x64), AppleWebKit/537.36, (KHTML, like 壁虎),Chrome/53.0.2785.143 Safari/537.36 & # 39; } proxy_ip =, { ,,,& # 39;https # 39;:, & # 39; https://115.28.148.137:8118& # 39; } html =, requests.get (“http://www.baidu.com",,头=头,代理=proxy_ip) html print print html.text
二,通过修改proxy_ip参数的代理IP服务器地址,可以更改代理IP
三,报错提示
requests.exceptions。ProxyError: HTTPSConnectionPool(主机=& # 39;www.baidu.com& # 39;,端口=443):马克斯重试超过url:/(ProxyError所致(& # 39;不能连接到代理公司,,错误(10054 & # 39;& # 39;)))
出错的原因一般有2个:
1, ip代理服务器不能正常使用
2, ip代理使用的协议不正常,例如http://和https://是不能写错的
如果是http代理服器的话,则如下写:
proxy_ip =, { ,,,& # 39;http # 39;:, & # 39; http://115.28.148.137:8118& # 39; }
如果是https代理服务器的话,则如下写法:
proxy_ip =, { ,,,& # 39;https # 39;:, & # 39; https://115.28.148.137:8118& # 39; }