相关疑难解决方法(0)

硒与scrapy动态页面

我正在尝试使用scrapy从网页上抓取产品信息.我的待删节网页如下所示:

  • 从包含10个产品的product_list页面开始
  • 点击"下一步"按钮加载下10个产品(两个页面之间的网址不变)
  • 我使用LinkExtractor跟踪每个产品链接到产品页面,并获得我需要的所有信息

我试图复制next-button-ajax-call但是无法正常工作,所以我试试了selenium.我可以在一个单独的脚本中运行selenium的webdriver,但我不知道如何与scrapy集成.我应该把硒部分放在我的scrapy蜘蛛里?

我的蜘蛛非常标准,如下所示:

class ProductSpider(CrawlSpider):
    name = "product_spider"
    allowed_domains = ['example.com']
    start_urls = ['http://example.com/shanghai']
    rules = [
        Rule(SgmlLinkExtractor(restrict_xpaths='//div[@id="productList"]//dl[@class="t2"]//dt'), callback='parse_product'),
        ]

    def parse_product(self, response):
        self.log("parsing product %s" %response.url, level=INFO)
        hxs = HtmlXPathSelector(response)
        # actual data follows
Run Code Online (Sandbox Code Playgroud)

任何想法都表示赞赏.谢谢!

python selenium scrapy web-scraping selenium-webdriver

74
推荐指数
1
解决办法
7万
查看次数