【发布时间】:2013-11-15 01:25:45
【问题描述】:
我的 html 看起来像这样:
<h1>Text 1</h1>
<div>Some info</div>
<h1>Text 2</h1>
<div>...</div>
我了解如何使用来自 h1 的 scrapy 信息进行提取:
content.select("//h1[contains(text(),'Text 1')]/text()").extract()
但我的目标是从<div>Some info</div>中提取内容
我的问题是我没有关于 div 的任何具体信息。据我所知,它正好在<h1>Text 1</h1> 之后。我可以使用选择器在树中获取 NEXT 元素吗?元素,位于 DOM 树的同一层?
类似:
a = content.select("//h1[contains(text(),'Text 1')]/text()")
a.next("//div/text()").extract()
Some info
【问题讨论】:
标签: python html parsing dom scrapy