简体   繁体   English

使用 Chrome 驱动程序保存谷歌登录

[英]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!谢谢!

your login information like cookies are stored in chrome profile.您的登录信息(如 cookies)存储在 chrome 配置文件中。

so to avoid re login prompts.所以避免重新登录提示。 Use the default profile which you uses for logging into gmail.使用您用于登录 gmail 的默认配置文件。

user-data-dir considers profile as default, and you don't have to specify that. user-data-dir 将配置文件视为默认配置,您不必指定它。 If its something else specify it through profile-directory argument如果它有别的东西通过配置文件目录参数指定它

Step to know profile path:了解配置文件路径的步骤:

open : chrome://version in address bar在地址栏中打开:chrome://version

在此处输入图像描述

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 data\Default你应该只提供直到用户数据不需要指定用户数据\默认

Update:更新:

copy the user data folder completely to eg c:\tmp\newdir将用户数据文件夹完整复制到例如 c:\tmp\newdir

open the copied user data (newdir) and search for folder called Default.打开复制的用户数据 (newdir) 并搜索名为 Default 的文件夹。 This is the profile folder.这是配置文件文件夹。

Now to use this:现在使用这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM