并非所有数据都在输出 Scrapy

Not all data in being outputted Scrapy

尝试抓取以下网站,https://www.trollandtoad.com/magic-the-gathering/aether-revolt/10066,它几乎完美地抓取了所有数据,但在某些情况下,某张卡有很多卖家,并且他们有一个显示查看更多的按钮,它不会获取不同卖家的所有价格,即使所有需要的数据都在 html 代码中,无论我是否点击查看更多。例如在下面的图片中,您将看到单击查看更多按钮之前和之后的卡片,它将刮掉 8 张卡片中的 7 张,唯一没有刮掉的是 7.99 的 Evo Merchant 卡,紧接着出现的一张我点了view more,下面两个,paradise games 2.98,evo merchant 6.99,getscraped就好了,不知道怎么回事

def parse(self, response):
        for game in response.css('div.card > div.row'):
            item = GameItem()
            item["Card_Name"]  = game.css("a.card-text::text").get()
            for buying_option in game.css('div.buying-options-table div.row:not(:first-child)'):
                item["Condition"] = buying_option.css("div.col-3.text-center.p-1::text").get()
                item["Price"] = buying_option.css("div.col-2.text-center.p-1::text").get()
                yield item

我认为你的问题出在你的 CSS 选择器上,特别是 :not(:first-child) 部分。

我没有仔细研究 HTML,但显然 "View More" link 之后的第一项也被认为是第一项 child。所以我会考虑以其他方式删除 table header:

for buying_option in game.css('div.buying-options-table div.row')[1:]: