[英]How to get cookies of a website using python
How can I get cookies of a website from browser using python? 如何使用python从浏览器获取网站的Cookie? The code currently being used is:
当前使用的代码是:
get_title = lambda html: re.findall('<title>(.*?)</title>', html, flags=re.DOTALL)[0].strip()
url = config.base_url
public_html = urllib2.urlopen(url).read()
print get_title(public_html)
cj = browsercookie.firefox()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
login_html = opener.open(url).read()
print get_title(login_html)
This code comes after the application has logged in. config.base_url = " https://10.194.13.71 " It is giving this error : c** File "/root/Desktop/mysonicwallnew/testservice.py", line 26, in test_service public_html = urllib2.urlopen(url).read() 该代码在应用程序登录后出现。config.base_url =“ https://10.194.13.71 ”它给出此错误:c **文件“ /root/Desktop/mysonicwallnew/testservice.py”,第26行,在test_service public_html = urllib2.urlopen(url).read()
CertificateError: hostname '10.194.31.71' doesn't match either of 'www.abc.com', 'abc.com' ** How do I fix this? CertificateError:主机名“ 10.194.31.71”与“ www.abc.com”,“ abc.com”都不匹配 **如何解决此问题?
This works for me - 这对我有用-
import requests
import browsercookie
import re
cj = browsercookie.chrome()
r = requests.get('http://stackoverflow.com', cookies=cj)
get_title = lambda html: re.findall('<title>(.*?)</title>', html, flags=re.DOTALL)[0].strip()
print r.content
print get_title(r.content)
Try updating question with the error you are facing or the exact thing you are looking for from the cookie to get more specific answers. 尝试使用您遇到的错误或您要从cookie中查找的确切内容更新问题,以获得更具体的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.