Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Chrome's cookies in Python-Requests

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

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.

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.

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

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

like image 938
TankorSmash Avatar asked Jul 29 '12 01:07

TankorSmash


People also ask

How do I extract cookies from a website?

For Google Chrome go to View > Developer > Developer Tools or CMD + ALT + I on Mac or F12 on Windows. ‍Now open the Application tab and check the cookies for each domain. Usually the cookies have names that resemble the name of the service they are being used by.


1 Answers

I created a module to load cookies from Firefox.

Example usage with requests:

import requests
import browser_cookie
cj = browser_cookie.firefox()
r = requests.get(url, cookies=cj)
like image 89
hoju Avatar answered Sep 28 '22 07:09

hoju