[英]Getting cookies saved by firefox with python
Is there any way to get cookies saved by Firefox with python code? 有什么办法让Firefox使用python代码保存cookie吗? I think its possible to interact with Firefox javascript interpreter with python but i don't know how. 我认为可以通过python与Firefox JavaScript解释器进行交互,但我不知道如何进行。
Actually i need firefox to browse a Web page, the Web page has some sort of authentications and finaly it makes a session key cookie, I want know cookie value and of course automatically with python. 实际上,我需要使用firefox来浏览网页,该网页具有某种身份验证,最后它使会话密钥成为cookie,我想知道cookie的值,当然也要通过python自动知道。
You can do it with selenium
, fire up a browser, navigate to a page, make the desired actions on a page and then use get_cookies()
to extract the cookies: 您可以使用selenium
做到这一点,启动浏览器,导航到页面,在页面上执行所需的操作,然后使用get_cookies()
提取cookie:
Returns a set of dictionaries, corresponding to cookies visible in the current session. 返回一组词典,对应于当前会话中可见的cookie。
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.google.com")
# do something else if needed
print(driver.get_cookies())
You can even dump and load cookies if needed: 您甚至可以根据需要转储和加载Cookie:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.