有没有办法用python代码获取Firefox保存的cookie?我认为可以使用 python 与 Firefox javascript 解释器进行交互,但我不知道如何进行交互。
实际上我需要firefox来浏览网页,网页有某种身份验证,最后它生成一个 session key cookie,我想知道cookie值,当然用python自动知道。
最佳答案
您可以使用selenium
来做到这一点,启动浏览器,导航到页面,在页面上执行所需的操作,然后使用 get_cookies()
提取cookie:
Returns a set of dictionaries, corresponding to cookies visible in the current session.
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.google.com")
# do something else if needed
print(driver.get_cookies())
如果需要,您甚至可以转储和加载 cookie:
关于javascript - 使用python获取firefox保存的cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41142806/