扫码关注官方订阅号
正在学习lxml,代码如下:
from lxml import etree text = ''' 洋鼹鼠 电子商务 天津 ''' html = etree.HTML(text) print(etree.tostring(html,encoding='utf-8').decode('utf-8'))
洋鼹鼠
电子商务 天津
输出如下:
洋鼹鼠 电子商务 天津
主要不理解为什么标签那里会出错呢?请问怎么解决这个问题?谢谢~
主要是因为
p元素内容分类 Flow content, palpable content.允许的内容 Phrasing content.允许的父元素任何接受flow content的元素
i元素Content catergories Flow content, phrasing content, palpable content.允许量 phrasing content.
很显然P元素的父元素应该是flow content类型的,然而i并不满足条件,也就是说这是不符合规范的。解决办法就是i直接换为p。
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
主要是因为
p元素
内容分类 Flow content, palpable content.
允许的内容 Phrasing content.
允许的父元素任何接受flow content的元素
i元素
Content catergories Flow content, phrasing content, palpable content.
允许量 phrasing content.
很显然P元素的父元素应该是flow content类型的,然而i并不满足条件,也就是说这是不符合规范的。
解决办法就是i直接换为p。