First IP address proxy mode
from urllib import request
If __name__ = = "__main__":
# access URL
URL = ' http://www.ahaoboy.cn:888/'
# This is proxy IP
proxy = {
# ' http ': ' 106.46.136.112:808 '
# ' H TTPs ': "https://112.112.236.145:9999",
"http": "Http://118.193.107.174:80"
}
# Create Proxyhandler
Proxy_support = Request. Proxyhandler (proxy)
# Create opener
opener = Request.build_opener (Proxy_support)
# Add user angent
Op Ener.addheaders = [(' User-agent ',
' mozilla/5.0 (Windows NT 6.1; Win64; x64) applewebkit/537.36 (khtml, like Gecko) chrome/56.0.2924.87 safari/537.36 ')]
# installation opener
Request.install_ Opener (opener)
# Use your own installed opener
response = Request.urlopen (URL)
# Read the information and decode
HTML = response.re AD (). Decode ("Utf-8")
# Printing Information
Print (HTML)
Second IP address proxy method
Import requests, Sys
url = ' http://jingcaiyuedu.com/'
Proxy = {
' http ': ' 121.43.170.207:3128 '
}
Try
Response = Requests.get (URL, proxies=proxy, timeout=1)
Print (Response.content.decode (' Utf-8 '))
Except Requests.exceptions.ConnectionError:
Print (' timeout ')
Python3 using IP Address proxy