如何從瀏覽器使用python獲取網站的cookie?目前正在使用的代碼是:如何使用python獲取網站的cookie
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)
此代碼來在應用程序登錄後 config.base_url =「https://10.194.13.71」 這是給這個錯誤:C **文件「/根/桌面/ mysonicwallnew /testservice.py」,第26行,在test_service 的public_html = urllib2.urlopen(URL).read()
CertificateError:主機名'10 .194.31.71' 不匹配的任一 'www.abc.com' ,'abc.com' ** 我該如何解決這個問題?
你試過'cookielib'嗎?參考:http://stackoverflow.com/a/189580/4350834 – Prabhakar
@Prabhakar:請找到編輯的問題 –
如果你只是想讀取餅乾,你應該嘗試 'r = requests.get(url) url ='https ://example.com/login' print r.cookies' – Prabhakar