获取或操纵Selenium Webdriver中的所有Cookie [英] Getting or Manipulating all cookies in Selenium Webdriver

查看:2697
本文介绍了获取或操纵Selenium Webdriver中的所有Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用Chromedriver和Python(或Java)混淆Cookie。

Trying to mess with cookies using Chromedriver with Python (or Java).

我想出了

for cookie in browser.get_cookies():
    print(cookie['name'] + ' --> ' + cookie['value'])

只向我提供与浏览器正在使用的活动网页相关的Cookie。

only gives me the cookies relevant to the active page my browser's on.

有没有任何方法,我可以使用Selenium或本机Python(在Ubuntu上,如果我需要进入文件系统),获取我的活动selenium会话的所有cookie?

Is there any method I can, using either Selenium or native Python (on Ubuntu, if I need to go into the file system), get all of the cookies on my active selenium session?

推荐答案

您可以提供一个userdir并从中提取cookie。

You can provide a userdir and extract the cookies from there.

co = webdriver.ChromeOptions()
co.add_argument("--user-data-dir=userdir")
browser = webdriver.Chrome(chrome_options = co) 

Cookie将以 userdir / Default / Cookies 这是一个SQLite3数据库。

The cookies will end up in userdir/Default/Cookies which is an SQLite3 database.

这篇关于获取或操纵Selenium Webdriver中的所有Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆