Using IP proxy pool to randomly generate an instance of IP in Python3 requests

Source: Internet
Author: User
This article mainly introduces the use of IP proxy pool Python3 requests in the random generation of IP instances, has a certain reference value, now share to everyone, the need for friends can refer to

Don't say anything, just go to the code!

# Encoding:utf-8import Requests # import requests module used to access test own ipimport Randompro = [' 1.119.129.2:8080 ', ' 115.174.66.148 ', ' 113.200.214.164 '] # the IP collected on (http://www.xicidaili.com/wt/) is used to test # The reason why the dictionary is not used is because the keys in the dictionary are unique HTTP and HTTPS can only exist one so it is not recommended to use the dictionary # Your request header information head = {  ' user-agent ': ' mozilla/5.0 (Windows NT 10.0; Win64; x64) applewebkit/537.36 (khtml, like Gecko) chrome/58.0.3029.110 safari/537.36 '}url = ' http://www.whatismyip.com.tw/' # The site you used to test your own IP request = requests.get (URL, proxies={' http ': Random.choice (Pro)}, Headers=head) # Let's ask this page Randomly generates a iprequest.encoding = request.apparent_encoding # Setting encoding encoding returns the request header encoding apparent_encoding Is the response content that is parsed from the content page print (request.text) # output returned content

Related Article

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.