requests to send data on reptiles and reptiles anti-learning process ---------- python

Requests to send data in ------------------ ------------------
Requests need to install the library: pip install requests
Post data requests occur in a very simple, just pass a dictionary corresponding to the transmission data,
It will automatically transmit internal data encoded to you, so also send get data
 
get request parameters
url='https://www.baidu.com/s?wd=123' 
head={'User‐Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKi t/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36'}
rep=requests.get(url,headers=head)
print(rep.text)

 

post request parameters
postData = { 'username':'Angela',
'password':'123456'
}
response = requests.post(url,data=postData)

 

Adding headers of User-Agent (identifier) ​​....
head={'User‐Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKi t/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36'}
rep=requests.get(url,headers=head)

Add others, such as: cookies, referer, too, in front of the anti-reptile urllib also introduced the

 

cookies acquisition method in requests library
url='https://www.baidu.com/'
req=requests.get(url)
req.cookies
<RequestsCookieJar[Cookie(version=0, name='B...省略

Save w cookie information can be opened with a built-in open method, used when needed to bring out

 
With session requests to save time you can no longer use cookies to specify parameters.
The session here is not stored in web development sessionsession returned cookies, cookies and use the complete network requests
 
= requests.session get_cookies () 
head = { '- Agent-the User': 'the Mozilla / 5.0 (the Windows NT 10.0; Win64; x64-) AppleWebKi T / 537.36 (KHTML, like the Gecko) the Chrome / 75.0.3770.142 Safari / 537.36'} 
URL = 'HTTPS: //www.baidu.com/' 
get_cookies.get (URL, headers = head) 
# now has a return information from cookies Baidu 
# we can call the cookies 
get_cookies.get (URL + 'S WD = 123?' , = head headers) 
<the Response [200 is]>

  

 

 

Guess you like

Origin www.cnblogs.com/lcyzblog/p/11269341.html