1

I'd like to set cookies to URL before parsing it with BS4. First of all, I'm not sure, if I'm using the correct format for cookies. Here is how they look like in chrome DevTool:

  • Name: aep_usuc_f
  • Value: site=rus&c_tp=USD&region=IE&b_locale=ru_RU

Here is my code:

url = 'https://example.com/item/123.html'
cookies = {'aep_usuc_f': 'site=rus&c_tp=USD&region=IE&b_locale=ru_RU'}

s = requests.Session()
s.post('https://example.com/item/123.html', cookies=cookies)
r = s.get('https://example.com/item/123.html')

soup = BeautifulSoup(r.text, 'lxml')

This doesn't seem to work. Cookies are not getting set. Appreciate your help.

Nazim Kerimbekov
  • 3,965
  • 6
  • 23
  • 48
  • 1
    You're first sending a POST request with cookies, and then sending a GET request with no cookies. What are you trying to achieve exactly? – glhr Apr 09 '19 at 10:07
  • I'm a newbie, so don't take my code too seriously. The default web page is in Russian and has currency of RUB. I want to change currency to USD and then parse the page with BS4. – Android_Minsky Apr 09 '19 at 10:28

1 Answers1

0

Since you just want to retrieve and parse the contents of the web-page, there's no need for a POST request here (see this post). Just use:

s = requests.Session()
r = s.get('https://example.com/item/123.html', cookies=cookies)
glhr
  • 3,982
  • 1
  • 13
  • 24