Reputation: 110093
When I go to Amazon.com in my browser, it sets a Cookie and then sends that as a header:
Connection:keep-alive
Cookie:x-wl-uid=1dxBAkbJJ9ys0awDahH9dLcLJmDR8XcztYvpl8p8Ojo8MNjbEo/ZBskQ8W/JSw7clLSM90d2OlFs=; session-token=/NCn9s4+YfWEyVyK0KIolKDyY2xx9L17aG/ZUZDY+5vH88wsk5n0+FcLDN9f/Y+xE/rNPKjev1iJrjSOgp26OVt5+EJynFZ6C/USFQkh3cXgzQkxXossA5Yxo9kD9S3yhpZbkZfGu1F63HNS1KQL/iIvchs3fvpMlDqmYXtiOn0H05ExWvcNdnio1ys8qU0W5LVosvUC45CuYQpi3n+7qi86AoHGjWHS/cm534xPcehsB+Xn0ndrWFNjVHSwNKR9; skin=noskin; ubid-acbjp=376-3466160-3751758; session-id-time=2082726001l; session-id=378-0276221-0879566; csm-hit=s-0GJW8D60QFN7XAX43CE2|1433025870016
Host:www.amazon.co.jp
How would I grab that cookie in order to insert it into my requests.get()
call? In other words, how would I do a request to fill in the cookie in the following:
headers = {
"Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding" : "gzip, deflate, sdch",
"Accept-Language" : "en-US,en;q=0.8,pt;q=0.6",
"Connection" : "keep-alive",
"Cookie" : "??????????",
"Host": "ww.amazon.com",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36"
}
Upvotes: 1
Views: 1028
Reputation: 4563
Create a session object, and then make requests from the context of that session:
s = requests.Session()
url = "http://www.amazon.com"
r = s.get(url)
Upvotes: 2