Xpath返回相同的结果

2024-10-17 06:13:08 发布

您现在位置:Python中文网/ 问答频道 /正文

试图使用Xpath从以下网站https://www2.trollandtoad.com/buylist/?_ga=2.123753418.115346513.1562026676-1813285172.1559913561#!/M/10591中删除卡片名称,但每次都返回相同的结果。我需要它输出链接中的所有卡片名称,但它只是一遍又一遍地给我相同的名称

def parse(self, response):
        #  Initialize item to function GameItem located in items.py, will be called multiple times
        item = GameItem()
        # Extract card category from URL using html code from website that identifies the category.  Will be outputted before rest of data
        for data in response.css('tr.ng-scope'):
            item["Set"] =data.css("a.ng-binding.ng-scope::text").get()
            if item["Set"] == None:
                item["Set"] = data.css("span.ng-binding.ng-scope::text").get()
            item["Card_Name"]  = data.xpath("//div/table/tbody/tr/td[contains(@class,'buylist_productname item')]/a/text()").get()

我尝试使用getall(),但也无法正常工作。它会返回所有的卡名,但它不会与我正确抓取的其他数据配对。而不是输出一张卡的名称,一个价格等等,它会给我所有的卡名称在一行连同价格的第一张卡等等


Tags: textin名称datagetresponsebeitem