为什么我不能使用scrapy在Amazon页面中选择一些元素?

2024-05-14 01:00:56 发布

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

我试图从下一页解析Amazon标准标识号(ASIN)。你知道吗

https://www.amazon.com/dp/B075GYWPCJ

但是,我无法从scrapy响应中选择包含ASIN的表。如何选择表以便分析表中的数据?你知道吗

import scrapy
from scrapy.crawler import CrawlerProcess

class AmazonSpider(scrapy.Spider):
    name = 'amazon.com'
    def start_requests(self):
        yield scrapy.Request('https://www.amazon.com/dp/B075GYWPCJ', self.parse)
    def parse(self, response):
        # This works.. :)
        print(response.xpath('//table[@id="HLCXComparisonTable"]'))
        # This doesn't work.. :(
        print(response.xpath('//table[@id="productDetails_detailBullets_sections1"]'))

process = CrawlerProcess()
process.crawl(AmazonSpider)
process.start()

Tags: httpsimportselfcomamazonresponsedefwww