H
H
hesy2019-03-06 19:57:56
Python
hesy, 2019-03-06 19:57:56

How to "unstick" words in nested tags?

The essence of the question is in the title.
Code:

html = '<span itemprop="text">Lorem ipsum dolor sit amet <a href="">consectetur adipiscing</a> elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </span>'
soup = BeautifulSoup(html)
result = soup.find("span",itemprop="text")

# Результат: "ametconsectetur adipiscing" ссылка приклеилась. Как поставить пробел?
# Lorem ipsum dolor sit ametconsectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Melnikov, 2019-03-06
@Mi11er

Maybe I didn't understand something. But everything seems to be ok.

soup = bs4(html,'lxml')
res = soup.find('span')
res.text
'Lorem ipsum dolor sit amet consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. '

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question