在Python请求中使用Chrome的Cookie [英] Using Chrome's cookies in Python-Requests

查看:1343
本文介绍了在Python请求中使用Chrome的Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用我收到的Cookie登入 http://www.steampowered.com 网站我的Chrome会话。

I'm trying to log in to the http://www.steampowered.com website using the cookies I've got from my Chrome session.

一旦我抓取了所有的 cookie 表的数据,使用命令 SELECT * FROM cookie WHERE host_key LIKE'%steam%'和列名: PRAGMA table_info(cookie),并使用列表理解对所有数据排序,我不知道如何将它全部传递到请求,以使cookie变得可用。

Once I've grabbed all the cookie table's data, using the command SELECT * FROM cookie WHERE host_key LIKE '%steam%' and the column names: PRAGMA table_info(cookie) and sorted through all the data with a list comprehension, I don't know how to pass it all to requests so that the cookies become usable.

code>请求的文档说你需要传入一个字典,即 cookies = {'cookies':'are_working'} ,但是一些键 name 互相覆盖,因为名称中的一些是: Steam_Language ,尽管它们不同

The request's docs say you need to pass in a dict, ie cookies={'cookies':'are_working'} but then some of the keys names overwrite each other, since a few of the names are : Steam_Language, though they're different hosts.

编辑:刚刚找到这可能会帮助我,但我不知道如何格式化cookie cookie cookielib

edit: Just found How to add cookie to existing cookielib CookieJar instance in Python? which might help me out, but I don't know how to format the Chrome cookies for cookielib

我的问题是:如何将多个不同的网站的Cookie传递到请求?

My question is: How do I pass several different sites worth of cookies to requests?

推荐答案

我创建了

I created a module to load cookies from Firefox.

请求的示例用法:

import requests
import browser_cookie
cj = browser_cookie.firefox()
r = requests.get(url, cookies=cj)

这篇关于在Python请求中使用Chrome的Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆