在Scrapy中的元素之间剪贴文本



我正在使用Scrapy,我正试图刮出这样的东西:

<html>
<div class='hello'>
some elements
.
.
.
</div>
<div class='hi there'>
<div>
<h3> title </h3>
<h4> another title </h4>
<p> some text ..... </p>
"some text without any tag"
<div class='article'>
some elements
. 
.
</div>
<div class='article'>
some elements
. 
.
</div>
<div class='article'>
some elements
. 
.
</div>
</div>
</div>
</html>

如果我想从类名为"hi there"的div下、类名为"article"的div之前的所有元素中提取文本,有没有任何可能的方法可以使用XPath或CSS选择器?

从未使用过Scrapy。

不知道它有什么功能,但是,

//div[@class='hi there']/div/(div[@class='article'])[1]/preceding-sibling::*

挑选div之前的元素;文章";类别和,

//div[@class='hi there']/div/(div[@class='article'])[1]/preceding-sibling::text()

在文章div.之前给你内部文本

最新更新