python reptile (six) Cookie

What is a Cookie

After the Web site, http requests are usually stateless (the first and the server connection and log in, then the server knows which user, but when the second request to the server, the server still does not know which user is currently requested ), cookie is to solve this problem, after the first login server, the server returns the data associated with just user (ie cookie) to the browser, the browser cookie will be stored locally, when the user requests a second server when will the last stored cookie automatically carried to the server, through the cookie you will know which user is currently. cookiede limited data storage, different browsers storage size. Generally not more than 4kb.

In some reptiles, we need to sign in before entering a page, like everyone, we want to browse Dapeng home page for all network, we must first register login before you can browse, then when reptiles, how Stay signed in it?

We need to add cookie in the request header.

We right-click on the page - Select View element - then select network- refresh select the first and then find the cookie profile-

 

 

 

 The cookie placed outside of our code request header

# How to use the cookie to remain logged in 
from urllib Import Request 
dapeng_url = ' http://www.renren.com/880151247/profile ' 

headers = {
     ' the User-Agent ' : " Mozilla / 5.0 (Windows NT 10.0; WOW64) AppleWebKit / 537.36 (KHTML, like the Gecko) the Chrome / 63.0.3239.132 Safari / 537.36 " ,
     ' cookies ' : "anonymid=k71toeni-kgxl6w; ick=15da19e2-eda3-436b-bbff-75e5ed22675a; t=2e83d3955db7ebed31b7aa451ce1fc3e6; societyguester=2e83d3955db7ebed31b7aa451ce1fc3e6; id=973827756; xnsid=83d505c7; XNESSESSIONID=96f6169a931b; JSESSIONID=abcnUOS-mxGHLfAakl8bx; depovince=GW; jebecookies=06d125d2-feee-42d3-b3dd-c2d44c83ca52|||||; ver=7.0; loginfrom=null; taihe_bi_sdk_uid=e1ab093fade1d5f67bb87b09690c33ec; taihe_bi_sdk_session=b22cdcce97f748cdd571ae2dd15f35c0; jebe_key=3f1e8e5f-c442-44f0-913c-b5724bf5f271%7C92df3a4ff360db67ebedb3fcbe322fc1%7C1582631331810%7C1%7C1582631331959; jebe_key=3f1e8e5f-c442-44f0-913c-b5724bf5f271%7C92df3a4ff360db67ebedb3fcbe322fc1%7C1582631331810%7C1%7C1582631331961; wp_fold=0"
}
req=request.Request(url=dapeng_url,headers=headers)
resp=request.urlopen(req)
print(resp.read().decode('utf-8'))

Dapeng we can enter the home page while holding the log

 

Guess you like

Origin www.cnblogs.com/zhaoxinhui/p/12363622.html