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