V
V
Vl6562020-10-21 18:48:16
Python
Vl656, 2020-10-21 18:48:16

In BeautifulSoup, when parsing, instead of text, some parameters are displayed in {{}}. How to fix it?

I have a task: to parse special offers from the AVON website.
When executing this code:

import requests
from bs4 import BeautifulSoup as BS
url = "https://my.avon.ru/specialnye-predlozhenija/19/vse-spetspredlozheniya"
r = requests.get(url)
html = BS(r.content, "html.parser")
obj = html.find('a', attrs={"class": "SpecialOfferTitle"})
print(obj)

tag text displays {{::MaxText(specialOffer.Headline, (Lay...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Karbivnichy, 2020-10-21
@Vl656

We press F12 and carefully study the requests (especially xhr). After carefully studying, we make a script request to the address " my.avon.ru/api/specialoffersapi/getcategorypromotions?promoCategoryId=19 ", we get the finished json and work with it.
5f905bd8c9526239597148.png

K
kirillinyakin, 2020-10-21
@kirillinyakin

Most likely, these attributes are displayed after working out JS scripts, and requests cannot handle this. You can try using Selenium

S
soremix, 2020-10-21
@SoreMix

Content is rendered via JS.
See the source code only through Ctrl+U.
To find where the information you need comes from, press F12 -> Network -> refresh the page. In the XHR tab, see what requests are sent and what responses they receive. Find the one you need, repeat it through requests
In your case, the URL will be

https://my.avon.ru/api/specialoffersapi/getcategorypromotions?promoCategoryId=19

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question