I have a site with multiple cities. The task is to parse the price from the certain city. How do I get cookies from browser and how to pass it into requests.get(url=url, headers=headers, cookies=cookies
?
Asked
Active
Viewed 108 times
0

Beginner
- 39
- 4
-
There are multiple browser extension for this. Just find and install one of them to download your browser cookies. – Feline Jan 24 '23 at 22:08
-
Does this answer your question? [How to send cookies in a post request with the Python Requests library?](https://stackoverflow.com/questions/7164679/how-to-send-cookies-in-a-post-request-with-the-python-requests-library) – py660 Jan 24 '23 at 22:11
1 Answers
0
Usually, cookies are sent to the server via the cookie header, which is part of the HTTP request. Here is an example of some python code that sends a cookie to the server.
import requests
cookies = {'key': 'value'}
r = requests.get("https://example.com", cookies=cookies)

py660
- 138
- 11
-
1that's ok, but how can I get cookies with certain city through developer panel on the site? – Beginner Jan 24 '23 at 22:11
-
Please elaborate on what you mean by "city". I'm assuming that you are using python3 as a client. – py660 Jan 24 '23 at 22:12
-
1I have a website with doors. I need to parse all prices from this website but from the certain city. I need to use cookies with this city to get an appropriate prices. The question is: how do I get this cookies? When I use response.cookies.get_dict() I get cookies of the default city. So I guess I need to copy these cookies from the developer panel on the site, but i don't know how to get this. – Beginner Jan 24 '23 at 22:20
-
Do you need to set a cookie named "city" and set it to something like "New York" to get the appropriate prices? If so, then just use the above example and replace "key" with the required cookie name, and "value" with the necessary value (such as "New York"). – py660 Jan 24 '23 at 22:25
-
1it has format like this: {'BITRIX_SM_PK': 'page_region_omsk', 'CITY': '%D0%9E%D0%BC%D1%81%D0%BA', 'CITYCODE': 'omsk', 'PHPSESSID': 'rmcoh5lmnjvcclbop3504l8b51'} – Beginner Jan 24 '23 at 22:27
-
If this is the data coming *from* the website, then you'll need to look into their API and find out how to change the CITY parameter. If it's cookie data sent *from* your program, then try the example above again. I noticed a "PHPSESSID" cookie in the data, so I'm guessing that the cookies were generated from the website running PHP using sessionStorage. – py660 Jan 24 '23 at 22:37
-
Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/251375/discussion-between-py660-and-beginner). – py660 Jan 24 '23 at 22:41