【发布时间】:2018-05-18 06:07:17
【问题描述】:
【问题讨论】:
标签: python python-3.x google-chrome
【问题讨论】:
标签: python python-3.x google-chrome
希望我没看错你的问题。
您可能想问“我如何读取已经存储在浏览器中的 cookie?”。我认为你做不到。但是 Selenium 会让你访问一个新的浏览器会话,通过它你可以获得更多的 cookie。
感谢 Sraw 的指点,我现在已经尝试过了,但它不会将我的登录信息转移到请求 API。所以也许在现代网站上是不可能的,或者 OP 可以尝试这些工具,因为他们的问题比我们的更清楚。
导入请求 导入浏览器cookie url = "https://stackoverflow.com/questions/50404771/python-get-cookiesof-a-website-saved-in-a-browser-chrome-firefox" res=requests.get(url) cj = browsercookie.chrome() res2 = requests.get(url, cookies=cj) 重新进口 get_title = lambda html: re.findall('(.*?)', html, flags=re.DOTALL)[0].strip() get_me = lambda html: re.findall('John', html, flags=re.DOTALL) # 此时我已经删除了我的答案,所以这什么都没有 # 现在我的答案已恢复,它会返回我,但不会代替登录按钮。 打印(len(get_me(res2.text)))【讨论】: