Python3 using IP Address proxy

Source: Internet
Author: User

  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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.