One, code example
#-*-Coding:utf-8-*-import requestsheader = {' user-agent ': ' mozilla/5.0 (Windows NT 6.1; Win64; x64) applewebkit/537.36 (khtml, like Gecko) chrome/53.0.2785.143 safari/537.36 '}proxy_ip = {' https ': ' https://115.28.1 48.137:8118 '}html = Requests.get ("http://www.baidu.com", Headers=header, proxies=proxy_ip) print Htmlprint Html.text
|
Second, by modifying the proxy IP server address of the PROXY_IP parameter, you can change the proxy IP
Third, error notification
Requests.exceptions.ProxyError:HTTPSConnectionPool (host= ' www.baidu.com ', port=443): Max retries exceeded with URL:/( Caused by Proxyerror (' Cannot connect to proxy ', error (10054, '))) |
There are generally 2 reasons for the error:
1. IP Proxy Server is not working properly
2, IP proxy use of the protocol is not normal, such as HTTP//and https://can not be written wrong
If it is an HTTP proxy, then write as follows:
proxy_ip = {' http ': ' http://115.28.148.137:8118 '}
If it is an HTTPS proxy server, the following is the wording:
Proxy_ip = {' https ': ' https://115.28.148.137:8118 '}
Python uses IP proxy examples and error resolution methods