所以我對 scrapy 完全是新手,并試圖學習 scrapy。https://www.killertools.com/Dent-Removal-Aluminum-Steel_c_11.html 對于初學者,如果有超過一頁的產品可供瀏覽,我想從兩個頁面中的第一類別中的所有產品中刪除項目名稱。這就是我得到的并且有效:import scrapyclass QuotesSpider(scrapy.Spider): name = 'killertools' start_urls = ['https://www.killertools.com/Dent-Removal-Aluminum-Steel_c_11.html', ]def parse(self, response): for item in response.css('div.name'): yield {'Name': item.xpath('a/text()').get()} next_page = response.css('div.paging a:nth-child(4)::attr("href")').get() if next_page is not None: yield response.follow(next_page, self.parse)但我想進入每個產品鏈接并提取項目描述并將它們作為描述放入詞匯表中。我該如何去做呢?我嘗試過這樣的事情:import scrapyclass QuotesSpider(scrapy.Spider): name = 'killertools' start_urls = ['https://www.killertools.com/Dent-Removal-Aluminum-Steel_c_11.html', ]def parse(self, response): for item in response.css('div.name'): yield {'Name': item.xpath('a/text()').get()} detail_page = response.css('div.name a::attr("href")').get() if detail_page is not None: yield response.follow(detail_page) for detail in response.css('div.item'): yield {'Description': detail.xpath('p/strong/text').get()} next_page = response.css('div.paging a:nth-child(4)::attr("href")').get() if next_page is not None: yield response.follow(next_page, self.parse)但它做了一些奇怪的事情,在我的水平上我無法真正理解這些事情。
添加回答
舉報
0/150
提交
取消