selenium实现chrome多开

有时候为了避开登录验证所带来的麻烦,先登录后用selenium预加载之前的用户配置及cookie信息会极大便利自动化目标的实现,但受限于selenium及chrome的用户配置文件加锁机制,每次只能有一个进程操作大大限制了自动化目标的实施。所幸可以通过chrome的多用户可以完成selenium多任务同时加载cookie信息

1、添加多个chrome用户
2、分别用不同chrome用户访问 chrome://version/,找到对应的 个人资料路径 一般新开的会将Default延伸为Profile 1~
3、声明用户配置信息路径及资料名称:
option.add_argument(‘–user-data-dir=C:\Users\Administrator\AppData\Local\Google\Chrome\User Data’)
option.add_argument(‘–profile-directory=Profile 1’)

参考资料:

https://stackoverflow.com/questions/50635087/how-to-open-a-chrome-profile-through-user-data-dir-argument-of-selenium