简体   繁体   English

如何使用python获取网站的cookie

[英]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.

相关问题 使用 python (Safari) 从网站获取 cookies - Get cookies from website using python (Safari) 如何使用python获取保存在文件中的cookie? - How to get the cookies saved in a file by using python? 使用python中的请求从网站获取cookie - Get cookies from website with requests in python 如何在Python 3 Flask网站上处理Python 2 cookie? - How to deal with Python 2 cookies on a Python 3 Flask website? Python 请求:使用 POST 和 Cookie 登录网站 - Python Requests: Logging into website using POST and Cookies 如何使用python模块“mechanize”使用chrome扩展名“cookies.txt export”导出的cookies.txt登录网站? - How to login a website using python module “mechanize” with a cookies.txt exported by the chrome extension “cookies.txt export”? 如何使用 tomcat AccessLogValve 记录 python 请求 cookies? - How to get python requests cookies logged using tomcat AccessLogValve? 如何使用 python 请求获取本网站的 html? - How to get the html of this website using python requests? Python-获取保存在浏览器中的网站的Cookie(Chrome / FireFox) - Python- Get cookies of a website saved in a browser (Chrome/FireFox) 如何使用python中的Scrapy抓取网站以获取网站中的所有链接? - How to crawl a website to get all the links in a website using Scrapy in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM