python reptile simulation using the login cookie

# ! /Usr/local/bin/python3.7 
Import the urllib.request
 Import The urllib.parse
 Import SSL 

# global cancel the certificate verification 
ssl._create_default_https_context = ssl._create_unverified_context
 # send the requested address 
URL = ' HTTPS: //www.xxxxxx. CN / Community / Questions / ASK ' 
# request header using log cookie analog 
headers = {
     ' the User-- Agent ' : ' the Mozilla / 5.0 (the Macintosh; the Intel the Mac the OS X-10_15_2) AppleWebKit / 605.1.15 (KHTML, like the Gecko) Version / 13.0.4 Safari / 605.1.15 ' ,
     ' the cookie ' :'Hm_lpvt_8decfd249e4c816635a72c825e27da1a = 1581998978; Hm_lvt_8decfd249e4c816635a72c825e27da1a = 1581836896,1581906456,1581998809,1581998853; _ga = GA1.2.1949167017.1580877792; _gat_UA-127576832-1 = 1; _gid = GA1.2.386004501.1581837085; laravel_token =% 3D; speedtest_session = eyJpdiI6ImFtNDlhaGMwRUJZWXYyZVZneHFPMlE9PSIsInZhbHVlIjoiUDR1Y2pLRThWZlh1K3lcL1N2bzFucnEyMmM2Qnp0Wnlqd0dcL1RnUHg2XC9CTnllb0FwUmtiYjlJUXR5QThBdU02YiIsIm1hYyI6ImQ4Mzk4YWY2NjQ3M2M0NmNmZDE3Njk2NDc1Yjc2ZTdhNjZhYTAzY2EyYTY1OWE2MWRjYmQ0YzFiNDQ1NDk0ZDYifQ% 3D% 3D; CNZZDATA1274897717 = 1649248696-1580888239-null% 7C1581994444; remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d = eyJpdiI6InZGd2ZSanhEMktvbnJZbk56TVFKQ1E9PSIsInZhbHVlIjoiYkJPUUNvUjg0V3VoellqWXFTZGFtQ0lHRnF0MFN0N0Q5SHJWQW9MTTY3RHJCbW9Va2F6N3FSQ2VhQmYzTkNnMkRpMlwvVDl0QUtPSGNQUG93UXNhYTloQTZLM1VWcTFGVUtnVUM1bTNTbk11d09QV0NOYVNJVE1oSDE1Nk85UFpsM3hRNVFlM1o1Nm00T0tBWDhoakZPeFJVQUdmYnhsYjFWSG5ib3ZVMUJCWmVIMDdaMjBGVnhQclhpUEFIK2Q1MiIsIm1hYyI6IjI4Yjk5MGJhY2I3OTgxY2YyYTdlZGMwOTJjYmUyNDVmZmUzODAwYzRhYjkxZjc3OTRiMDMyZWI3YzYyODI2ODEifQ% 3D% 3D;' , 
    
} 
# Creation request 
Request = urllib.request.Request (URL, headers = headers)
 # sends a request 
Response = the urllib.request.urlopen (Request) 

# save information returned 
with Open ( ' / the Users / mozili / PYTHONWORKSPACE / Reptile /login.html ' , ' WB ' ) AS FP: 
    fp.write (response.read ())

 

note:

1, cookie by sending the request, the obtained capture tool, such as fiddler or charles

2, cookie here is not a cookie is sent when the login request, cookie that page but you want to access through the login request

3, not necessarily all of the sites can be achieved through the cookie to log on, such as those large sites with many parameters, to achieve good sign in the ordinary method is suitable for some small simple sites

4, if some sites can not be achieved only added a cookie login, you can try the additional information request headers also add to the mix log

Guess you like

Origin www.cnblogs.com/lxmtx/p/12633672.html