当前位置:网站首页>Selenium builds cookies pool to bypass authentication and anti crawl login

Selenium builds cookies pool to bypass authentication and anti crawl login

2022-06-26 08:52:00 Feng Dashao

   The previous blog introduced , Today's Internet developers are trying to reduce the impact of various crawlers on servers , Various anti climbing mechanisms have been adopted . Recently someone raised a question , Algorithm cracking without verification code , How to complete Selenium Fully automatic login ? In fact, since there is an anti climbing mechanism , There must be every way to crack it , It's just that the complexity of each is different . Today I will introduce a more direct method , By building Cookies Pool to bypass the verification step .


   Cookie It is a short text file stored by the browser on the user's computer . The encrypted user information is stored in this file (User ID, Password), Expiration time (Expired Date/Time) wait .


   because Cookie There is an expiration date , chart 1,t because Cookies involve User/Password, Here is the code of the occlusion part . When it fails , You need to log in again , Generate a new Cookie. Simple understanding , It is like a Hong Kong and Macao pass , After the validity of the visa , You have to sign again before you can use .


   Therefore, we must first complete a manual normal login , Automatic system generation Cookies, And then through response.cookies() Method to get directly , Of course , If you are not familiar with fast extraction through code , You can also manually copy and paste , More time-consuming .


   By getting Cookies after , First add an empty lst, Then put multiple Cookies To form an independent dict, Add to this empty by looping lst in , Formed a Cookies pool , chart 2


   Quickly set up Cookies Behind the pool , When we open the corresponding URL after , You can let the browser automatically add one by one through a loop Cookie, When I'm done , Refresh the browser , Code in :

Something to pay attention to ,add_cookie() Methodical params Must contain “Name” and " Value", Otherwise, an error will be reported . So in creating an independent Cookie, The format must be {‘name’:‘xxx’, ‘value’:‘xxxx’}, So it can be interpreted as name Equivalent to Cookie Of Key,value Equivalent to value ( Key_Value Key value pair ) .


   Last , Create a class , hold Selenium Set the properties of ,
hold Cookies pool , All the added methods are encapsulated in a custom function , Run it , You can achieve the effect of automatic login . A final reminder , dependent Cookies Don't give it to others , The code program must be encrypted and kept well , Because it's related User/Password There is a risk of being decompiled and stolen , Here we will not introduce how to compile Cookie Restore real information .


for i in cookies:
  browser.add_cookie(i)

browser.refresh()


chart 1

 Insert picture description here


chart 2

 Insert picture description here

原网站

版权声明
本文为[Feng Dashao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260830111580.html