首页 > 其他分享 >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-12-10 17:44:47浏览次数:42  
标签:__ head lxml etree url html line

在使用xpath,遇到了报错,记录下。

 

 (python中代码是没有问题)

from lxml import etree
import requests
from constants import headers


def run():
    # url = "http://www.gushiju.net/shici/guanyu/%E4%B8%89%E5%9B%BD%E6%BC%94%E4%B9%89"
    # page_text = requests.get(url=url, headers=headers).text
    tree = etree.parse("2.html")
    res = tree.xpath('/html/head/title')
    print(res)


if __name__ == '__main__':
    run()

 发现,其实是html文档有问题。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>hello world</h1>
</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" />

// 在每一个标签末尾加上“/”号

 

 

 

 

 执行成功了!

 

标签:__,head,lxml,etree,url,html,line
From: https://www.cnblogs.com/shaoyishi/p/16971974.html

相关文章

  • Pushing the Limits of Simple Pipelines for Few-Shot Learning: External Data and
    论文:https://hushell.github.io/pmf/本论文探究了以下问题:1.对外部数据进行预训练如何有利于FSL。2.如何利用最先进的transform架构。3.微调如何减轻domainshift。两......
  • System.CommandLine版CSRebot
    之前自己实现过一个CSRebot命令行工具,现在用System.CommandLine来实现,就规范和省事多了,虽然System.CommandLine还没有正式发布,但它的实现思路还是很不错的。下面的......
  • System.CommandLine版CSRebot
    之前自己实现过一个CSRebot命令行工具,现在用System.CommandLine来实现,就规范和省事多了,虽然System.CommandLine还没有正式发布,但它的实现思路还是很不错的。下面......
  • System.CommandLine版CSRebot
    之前自己实现过一个CSRebot命令行工具,现在用System.CommandLine来实现,就规范和省事多了,虽然System.CommandLine还没有正式发布,但它的实现思路还是很不错的。下面......
  • Qt:QLineEdit显示字符的4种方式
    基本信息:The​​QLineEdit​​widgetisaone-linetexteditor.Header:#include<QLineEdit>qmake:QT+=widgetsInherits:​​QWidget​​QLineEdit控件Qt提供的非常......
  • tekton pipline概念及调用流程
    概念:task:一个task即一个任务,一个任务运行一个podstep:一个task包含多个step。一个step包含一个容器taskrun: task引用taskrun来运行taskpipline:由多个task组成的pipline(流......
  • 2、tekton pipline参数调用流程
    变量定义的两种类型:1、string: 字符串类型2、数组类型 ......
  • 取相关系数大于0.3的决策树baseline
    模型在测试集的准确率为0.74提升了一些说明根据相关系数取模型是不错的选择。importmatplotlib.pyplotaspltimportnumpyasnpimportpandasaspdimportseaborn......
  • 直接用决策树跑baseline
    准确率是0.67,下一篇博客将去掉偏差大的特征。importmatplotlib.pyplotaspltimportnumpyasnpimportpandasaspdimportseabornassnsdf=pd.read_csv('train......
  • [未解决] write javaBean error, fastjson version 1.2.76, class org.springframewor
    本地测试正常,打包部署后报错如下:writejavaBeanerror,fastjsonversion1.2.76,classorg.springframework.security.web.header.HeaderWriterFilter$HeaderWriterResp......