python使用selenium打开chrome浏览器时带用户登录信息 |
您所在的位置:网站首页 › chrome无法登陆google账户的插件 › python使用selenium打开chrome浏览器时带用户登录信息 |
导读
我们在使用selenium打开google浏览器的时候,默认打开的是一个新的浏览器窗口,而且里面不带有任何的浏览器缓存信息。当我们想要爬取某个网站信息或者做某些操作的时候就需要自己再去模拟登陆 selenium操作浏览器这里我们就以CSDN为例,来展示如何让selenium在打开chrome浏览器的时候带上用户的登录信息 打开chrome浏览器 from selenium import webdriver from selenium.webdriver import ChromeOptions #设置操作的网站 web_url = "https://bbs.csdn.net" browser = webdriver.Chrome(executable_path=r"D:\chromedriver_win32\chromedriver\chromedriver.exe") #打开网页 browser.get(web_url)
因为安装chrome的时候是采用的默认安装路径,所以路径就和上面一样。如果安装的时候自定义了路径,就注意修改一下chrome.exe的路径。 user-data目录是chrome缓存数据的目录,里面包含了用户的登录信息。如果你是在你自己的电脑上使用,需要将15053修改成你自己的用户名。 注意:在执行上面命令的时候建议关闭chrome浏览器,否则后面在执行python程序的时候,可能无法连接到chrome。 使用selenium打开网站 from selenium import webdriver from selenium.webdriver import ChromeOptions web_url = "https://bbs.csdn.net" #加载cookies中已经保存的账号和密码 options = ChromeOptions() options.add_experimental_option("debuggerAddress", "127.0.0.1:9014") browser = webdriver.Chrome(executable_path=r"D:\chromedriver_win32\chromedriver\chromedriver.exe", chrome_options=options) browser.get(web_url)
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |