O
O
Ornitier2022-04-21 17:38:36
Python
Ornitier, 2022-04-21 17:38:36

How to get content tag from using bs4 python?

There is this snippet of html code:

<meta property="og:description" content="Студенческая ул., 187, Энгельс, Саратовская область" />

How can I detect the segment itself and extract the contents of the content tag from it using bs4 soup?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
igorzakhar, 2022-04-22
@igorzakhar

>>> from bs4 import BeautifulSoup
>>> html_chunk = '<meta property="og:description" content="Студенческая ул., 187, Энгельс, Саратовская область" />'
>>> soup = BeautifulSoup(html_chunk)
>>> desc = soup.find("meta", property="og:description")
>>> desc.get("content")
'Студенческая ул., 187, Энгельс, Саратовская область'
>>>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question