【python】报错lxml.etree.XPathEvalError: Invalid expression

在执行Python爬虫时遇到了`lxml.etree.XPathEvalError: Invalid expression`的错误,该错误出现在尝试使用XPath表达式解析HTML内容时。错误位于文件`hello_spider.py`的第6行,通过`ht.xpath(xpath)`执行。要解决这个问题,需要检查XPath表达式是否正确,并确保它符合XPath语法。
摘要由CSDN通过智能技术生成

报错信息:
Traceback (most recent call last):
File “c:\Users\86130\Desktop\Study\python\spider_learning\hello_spider.py”, line 6, in
text = ht.xpath(xpath)
File “src\lxml\etree.pyx”, line 1583, in lxml.etree._Element.xpath
File “src\lxml\xpath.pxi”, line 305, in lxml.etree.XPathElementEvaluator.call
File “src\lxml\xpath.pxi”, line 225, in lxml.etree._XPathEvaluatorBase._handle_result
lxml.etree.XPathEvalError: Invalid expression

源代码:

import lxml.html,requests
url = 'https://www.python.org/dev/peps/pep-0020/'
xpath = '//*[@id="the-zen-of-python"]/pre/text(&#x
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值