D
D
Dimchik2021-11-18 05:40:03
Python
Dimchik, 2021-11-18 05:40:03

Beautiful soup, how to get tag value by incomplete attribute value?

I need to get the text in a span tag by an incomplete class attribute value (because that part of the attribute value will change on the site).
Here is the code I have at the moment:

soup = BeautifulSoup(source.text, "html.parser")
    Currency = soup.find_all('a', {"href": '/invest/currencies/USDRUB/'})

    item = Currency[0]
    Name = item.find("span", {"class": "NameColumn__nameWrapper_LWKdK"}).get_text() # Сдесь мне нужно чтобы не было LWKdK
    item = Currency[2]
    Price = item.find(("span", {"class": "Money-module__money_UwC2N"})).get_text() # А сдесь UwC2N

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Python Newbie, 2021-11-18
@Dimpik

Import the module re: import re
And look like this:

Name = item.find("span", {"class": re.compile("Здесь частичный текст")}).get_text()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question