Scrapy - 选择除第一个之外的所有相同类别的表

时间:2017-11-07 10:01:38

标签: python web-scraping scrapy

除了第一个,我希望得到所有具有相同类别( tbl-cenik )的表格。我正在尝试这个答案select all "tr" except first "tr" in table 。但一切都是徒劳的。这是我的示例代码

response.css('.tbl-cenik:not(:first-child)')

我知道我可以这样做。

`response.css('.tbl-cenik:not(:first-child)')[1:]`

但这对我来说并不像是pythonic。我们可以用任何方式使用选择器吗?

2 个答案:

答案 0 :(得分:2)

您可以尝试以下

.tbl-cenik~.tbl-cenik

获取table@class="tbl-cenik"个节点,这些节点是第一个节点的兄弟节点(不包括第一个节点)

答案 1 :(得分:0)

如果你只想获得tbl-cenik类的所有表,但是第一个,那么

response.css('table.tbl-cenik')[1:]

足够和IMHO Pythonic足够了。但更好的方法是使用XPath:

response.xpath('//table[@class="tbl-cenik" and position() > 1]')
相关问题