循环通过ol标签的孩子与美丽的小屋
我有以下HTML结构:
<ol>
<li>...</li>
<div>...</div>
<li>...</li>
</ol>
当我执行以下操作时:
for e in doc.find('ol').children:
print(e.text)
我得到两个 li 元素,但 div
我该怎么做才能以正确的顺序获得所有这些?
I have the following html structure:
<ol>
<li>...</li>
<div>...</div>
<li>...</li>
</ol>
When I do the following:
for e in doc.find('ol').children:
print(e.text)
I get the two li elements but not the div
What can I do to get all of them in the correct order?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的脚本IST工作,您可以对其进行一些调整,然后打印标签的文本:
示例
输出
Your script ist working, you could adjust it a bit and just print the text of the tags:
Example
Output