Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 views
in Technique[技术] by (71.8m points)

python - Save google log-in with Chrome Driver

Hey I did a short script that logins on google. Every time it has to do the login as the infos are not saved. Is there any way to save the login infomations in order to avoid logging in every time but only when the authentication is expired?

I would do something like this:

driver = webdriver.Chrome(chrome_options=opt, executable_path=r'')
driver.get('https://www.gmail.com')
form = driver.find_element_by_id("identifierId")

if form==None:
   #do something else
else:
     login()

But do not how to save the tokens.

Thanks!

question from:https://stackoverflow.com/questions/65946257/save-google-log-in-with-chrome-driver

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your login information like cookies are stored in chrome profile.

so to avoid re login prompts . Use the default profile which you uses for logging into gmail.

user-data-dir considers profile as default , and you don't have to specify that . If its something else specify it through profile-directory argument

Step to know profile path:

open : chrome://version in address bar

enter image description here

Now to use this :

chrom_options.add_argument("user-data-dir=C:\Users\AppData\Local\Google\Chrome\User Data")

Note; you should give only till user data don't need to specify user dataDefault

Update:

copy the user data folder completely to eg c:mp ewdir

open the copied user data (newdir) and search for folder called Default . This is the profile folder.

Now to use this :

chrom_options.add_argument("user-data-dir=c:\tmp\newdir")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...