Python 未正确地刮取数据

Python 未正确地刮取数据,python,scrapy,Python,Scrapy,尝试使用Scrapy刮取以下网页,我正确刮取了部分数据,但无法正确刮取卡名,因为它的选择器与设置名称相同,所以我也只获取卡名的设置名称 def parse(self, response): # Initialize item to function GameItem located in items.py, will be called multiple times item = GameItem() # Extract card catego

尝试使用Scrapy刮取以下网页,我正确刮取了部分数据,但无法正确刮取卡名,因为它的选择器与设置名称相同,所以我也只获取卡名的设置名称

 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.css("a.ng-binding.ng-scope::text").get()
            # Call item again in order to extract the condition, stock, and price using the corresponding html code from the website
            item["Condition"] = data.css("td\.5557170.buylist_condition::text").get()
            item["Quantity"] = data.css("span.ng-binding::text").get()
            item["Price"] = data.css("span.ng-binding::text").get()
更新#1

我使用了xpath,并且能够得到一个卡片名而不是集合名,但是它为每一行返回相同的卡片名,而不是不同的卡片名

item["Card_Name"] = data.xpath("/html/body/div[2]/div[2]/div[1]/table[1]/tbody/tr[1]/td[2]/a/text()").get()
card\u names=response.xpath(//div/table/tbody/tr/td[contains(@class,'buylist\u productname item'))]/a/text()”).getall()
将根据不同卡片名称在页面中的顺序返回它们的列表。

card\u names=response.xpath(//div/table/tbody/tr/td[contains(@class,'buylist\u productname item'))]/a/text())。getall()

将根据不同卡片名称在页面中的顺序返回它们的列表。

以下代码最终使其正常工作,我必须精简xpath并使其成为相对的,而不是绝对的

item["Card_Name"]  = data.xpath(".//td[2]/a/text()").get()

下面的代码是最终使其正常工作的代码,我必须精简xpath并使其成为相对的,而不是绝对的

item["Card_Name"]  = data.xpath(".//td[2]/a/text()").get()