【发布时间】:2021-03-13 10:05:56
【问题描述】:
我正在处理一个 Django 项目,我需要在其中提取所有包含文本的元素以及该元素的 xPath。例如:
<html>
<head>
<title>
The Demo page
</title>
</head>
<body>
<div>
<section>
<h1> Hello world
</h1>
</section>
<div>
<p>
Hope you all are doing well,
</p>
</div>
<div>
<p>
<span>This is the</span> example HTML
</p>
</div>
</div>
</body>
</html>
输出应该是这样的:
/head/title: The Demo Page
/body/div/section/h1: Hello world!
/body/div/div[1]/p: Hope you all are doing well,
/body/div/div[2]/p: <span>This is the</span> example HTML
【问题讨论】:
标签: python html web-scraping lxml