[英]Text inside BR not fetch using python beautifulsoup
I would like to get all data inside div under br tags. 我想在br标签下的div中获取所有数据。 however it only fetch the text on the first . 但是它只获取第一个文本。
<div itemprop="description">
<p>Chars :
</br>- test1
</br>- test2
</br>- test3
</p>
</div>
script: 脚本:
tag = soup.find(itemprop="description").get_text()
output: 输出:
Chars
-test1
I want to get all text inside br 我想让所有文本都在br
I haven't had a problem with lxml and select 我没有lxml的问题,然后选择
from bs4 import BeautifulSoup as bs
html = '''
<div itemprop="description">
<p>Chars :
</br>- test1
</br>- test2
</br>- test3
</p>
</div>
'''
soup = bs(html, 'lxml')
data = [item.text.strip().replace('\n',' ') for item in soup.select('div[itemprop=description]')]
print(data)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.