F
F
freear2020-09-15 17:46:03
Python
freear, 2020-09-15 17:46:03

How to get text from several identical tags at the same time?

Hello. I am writing a parser in python and I ran into this problem: the description text is divided into several paragraphs, each of which is in a separate . All of them lie in one, but besides them, there is one more directory with text that I don’t need. So you need to extract the tact from these 'r' so that it is one whole description. .find_all(p).get_text doesn't work, find(div).get_text doesn't work because it still unloads unnecessary text from another directory in it. So far, I've only pulled out the product name, but how do I pull out the description from all <p>'s? : 5f60d344603a0547647169.jpeg

def get_content(text: str):
soup = bs4.BeautifulSoup(text, 'lxml')
items = soup.find_all('div', itemtype=" schema.org/Product ")
things = []
for item in items:
name = item.find('h1', itemprop="name").get_text()
except:
name = ''

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kostyan4ik, 2020-09-15
@freear

A = переменная.findAll('p')
Text = ''
for i in a:
    Text += i

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question