Example of python using IP Agent and error Resolution
Code examples
#-*-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.148.137:8118'}html = requests.get ("http://www.baidu.com", headers=header, proxies=proxy_ip) print htmlprint html.text
Second, you can change the proxy IP by modifying the address of the proxy IP server of the proxy_ip parameter.
Third, error warning
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 two reasons for errors:
1. The ip proxy server cannot be used properly.
2. The protocol used by the IP agent is abnormal, for example, http:// and https:// cannot be written wrong.
If it is a http proxy server, it is written as follows:
Proxy_ip = {'http':' http://115.28.148.137:8118'}
If it is a https proxy server, it is written as follows:
Proxy_ip = {'https':' https://115.28.148.137:8118'}