刚入门求指点
代码如下所示,运行后报错!
info = '\n'.join(e.xpath('\\div[@class="m-post"]/p/test()'[0]))
title = e.xpath('//h1/test()')[0]
next_url = f'https://z8888888888{e.xpath("//tr/td[2]/a/@href")[0]}'
# print(info)
# print(title)
with open('*****.txt', 'w', encoding='utf-8') as f:
f.write(title + '\n\n' + info + '\n\n')
if next_url == '/book/douluodalu/':
break
错误内容如下
Traceback (most recent call last):
File "D:\pycharm\main.py", line 385, in
info: str = '\n'.join(e.xpath('\div[@class="m-post"]/p/test()')[0])
File "src\lxml\etree.pyx", line 1599, 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
哪位能帮我指点迷津?谢谢