具有 beautifulsoup 的 html 元素的文本和元素数据的有序列表
Ordered list of text and element data of an html element with beautifulsoup
我想用 BeautifulSoup (bs4) 解析以下 div 元素的内容:
<div><!--block--> Some text is here <br> - Another text <br> - More text <br> </div>
我需要内容的有序列表。对于这种情况,列表应包含以下项目:
- non-breaking space
- non-breaking space
- text data
- br
- non-breaking space
...
- non-breaking space
使用 tag.find_all() 我可以获得像 "br" 这样的标签列表,但是 [=21 不会返回所有其他数据,例如不间断 space 或文本数据=]().
tag.contents 正是我要找的。
我想用 BeautifulSoup (bs4) 解析以下 div 元素的内容:
<div><!--block--> Some text is here <br> - Another text <br> - More text <br> </div>
我需要内容的有序列表。对于这种情况,列表应包含以下项目:
- non-breaking space
- non-breaking space
- text data
- br
- non-breaking space
...
- non-breaking space
使用 tag.find_all() 我可以获得像 "br" 这样的标签列表,但是 [=21 不会返回所有其他数据,例如不间断 space 或文本数据=]().
tag.contents 正是我要找的。