python - 从纯文本获取 Xpath
问题描述
我试图从文本而不是 URL 中获取 xpath。但我不断收到错误“AttributeError:'HtmlElement'对象没有属性'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)
解决方案
推荐阅读
- c++ - 多行宏导致“预期声明”错误
- javascript - 如何在没有 cocoapod 的情况下在 0.60.0 版中创建反应原生应用程序?
- jquery - Ajax formdata文件上传进度百分比
- javascript - 使用 window.open 后更改 HTML 属性
- java - 在 onCreate 中初始化变量,但在 onResume() 中更新它们
- python-2.7 - Python smtplib 电子邮件不会发送到外部地址
- excel - 连续计算多个日期范围内的唯一日期
- javascript - Child_Processes 从 javascript 节点 js 调用函数到 python 中断导入
- angular - 在Angular中使用ngFor在表中生成多行
- python - 从科学杂志获取 xpath 时遇到问题,它返回一个没有元素的列表