当前位置:网站首页>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:24:00 Star and Dream Star_ dream

Python Reptiles Problems encountered in :

 

Python Code ( There's nothing wrong with it , yes HTML There is a problem with the document ) 

from lxml import etree

#  Access to the local HTML file 
html = etree.parse(r" test .html")

result = etree.tostring(html, encoding='utf-8').decode('utf-8')

print(result)

HTML file ( Error message

<!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 Of parse Method </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>

Solution : 

Focus on modifying this part

  After modification :

<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

Add “/” Number

  Successful execution :

 

End

原网站

版权声明
本文为[Star and Dream Star_ dream]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050519129937.html