当前位置:网站首页>lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
2022-07-05 05:19:00 【星与梦想star_dream】
Python爬虫中遇到的问题:
Python代码(本身没有错,是HTML文档有问题)
from lxml import etree # 获取本地HTML文档 html = etree.parse(r"测试.html") result = etree.tostring(html, encoding='utf-8').decode('utf-8') print(result)
HTML文档(出错信息)
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>etree的parse方法</title> </head> <body> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> <li>7</li> <li>8</li> <li>9</li> <li>10</li> </ul> </body> </html>
解决方案:
重点修改该部分
修改后:
<meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
在每一个标签末尾加上“/”号
成功执行:
完
边栏推荐
- Simple HelloWorld color change
- Download and use of font icons
- [turn to] MySQL operation practice (I): Keywords & functions
- Unity writes timetables (without UI)
- [turn]: Apache Felix framework configuration properties
- Improvement of pointnet++
- Romance of programmers on Valentine's Day
- [LeetCode] 整数反转【7】
- YOLOv5添加注意力機制
- Ue4/ue5 illusory engine, material part (III), material optimization at different distances
猜你喜欢
[interval problem] 435 Non overlapping interval
[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research
Shell Sort
TF-A中的工具介绍
django连接数据库报错,这是什么原因
Bucket sort
JVM call not used once in ten years
Improvement of pointnet++
Unity ugui source code graphic
远程升级怕截胡?详解FOTA安全升级
随机推荐
[turn]: Apache Felix framework configuration properties
Django reports an error when connecting to the database. What is the reason
JVM call not used once in ten years
Haut OJ 1350: choice sends candy
Romance of programmers on Valentine's Day
The next key of win generates the timestamp file of the current day
Collapse of adjacent vertical outer margins
UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化
YOLOv5添加注意力机制
Use the command character to close the keyboard command of the notebook
Solon Logging 插件的添加器级别控制和日志器的级别控制
cocos2dx_ Lua particle system
Haut OJ 1241: League activities of class XXX
Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
Unity card flipping effect
Animation
Embedded database development programming (VI) -- C API
Cocos progress bar progresstimer
Research on the value of background repeat of background tiling
【ES实战】ES上的native realm安全方式使用