簡體   English   中英

帶有beautifulsoup的html元素的文本和元素數據的有序列表

[英]Ordered list of text and element data of an html element with beautifulsoup

我想用BeautifulSoup(bs4)解析以下div元素的內容:

<div><!--block-->&nbsp; &nbsp; Some text is here&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; - Another text&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; - More text&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div>

我需要一個有序的內容列表。 對於這種情況,該清單應包含以下項目:

- non-breaking space
- non-breaking space
- text data
- br
- non-breaking space
...
- non-breaking space

使用tag.find_all()我可以得到像“br”這樣的標簽列表,但tag.find_all()不會返回所有其他數據,如非破壞空格或文本數據。

tag.contents是我一直在尋找的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM