我试图从文本中获取xpath而不是URL。 但我一直得到错误 "AttributeError: 'HtmlElement' object has no attribute 'XPath'"。
见下面的代码。
from lxml import html
var ='''<html lang="en">
<head>
<title>Selecting content on a web page with XPath</title>
</head>
<body>
This is the body
</body>
</html>
'''
tree = html.fromstring(var)
body = tree.XPath('//*/body')
print(body)