Simple requests module usage

. 1  Import Requests
 2  Import Random
 . 3  
. 4  # URL request sent by the URL 
. 5 URL = ' https://www.baidu.com ' 
. 6  # request header information commonly used for camouflage browser, the server checking 
. 7 headers = {
 . 8  
. 9      ' the User-- agent ' : ' the Mozilla / 5.0 (the Windows NT 10.0; Win64; x64-) AppleWebKit / 537.36 (KHTML, like the Gecko) the Chrome / 75.0.3770.100 Safari / 537.36 ' 
10  }
 . 11  # Create a proxy ip pool, which is stored each agent ip data dictionary ({ 'protocol': 'ip: Port'}) 
12 is Proxies = [{ ' HTTP ': ' 127.0.0.0:8888 ' }, { ' HTTPS ' : ' 127.0.0.1:8848 ' }]
 13 is  
14  # GET request parameters (the latter parameter url) is required to carry 
15 the params = {}
 16  
. 17 requests.get ( URL = URL, the params = the params, headers = headers, Proxies the random.choice = (Proxies))    # random handover proxy IP 
18 is  # parameters (the form) carried POST request requires 
. 19 Data = {}
 20 is requests.post ( URL = URL, Data = Data, headers = headers, Proxies = The random.choice (Proxies))
 21 is  
22 is  #Creating a session request object, like requests usage, you can send get, post requests, and other settings can be stored in the session cookie object 
23 sess = requests.Session ()

 

Guess you like

Origin www.cnblogs.com/NoteBook3013/p/11109370.html