【问题标题】:Scrapy Splash Crawling Javascript WebsiteScrapy Splash 爬取 Javascript 网站
【发布时间】:2018-02-16 20:04:11
【问题描述】:

我可以使用以下代码抓取 Javascript 呈现的页面:

import scrapy
from scrapy_splash import SplashRequest

class QuotejscrawlerSpider(scrapy.Spider):
    name = 'quotejscrawler'

    def start_requests(self):
        yield SplashRequest(
             url = 'http://www.horsedeathwatch.com/',
             callback=self.parse,
         )

    def parse(self, response):
        for quote in response.xpath("//tr"):
            item = {
                'horse': quote.xpath('td[@data-th="Horse"]/a/text()').extract(),
                'date': quote.xpath('td[@data-th="Date"]/text()').extract(),
                'cause': quote.xpath('td[@data-th="Cause of Death"]/text()').extract(),
            }
            yield item

我想通过点击每个网页上的“下一步”按钮来抓取多个网页。我是新手。 有什么建议吗?

【问题讨论】:

    标签: python scrapy scrapy-splash


    【解决方案1】:

    据我所知,似乎有 2 种(非 Python)方法可以使脚本飞溅:

    • 通过js_source参数传递javascript代码
    • 通过lua_source 参数传递lua 代码(有一些examples 显示如何使用scrapy-splash 执行此操作)

    也就是说,我认为对网站发出的请求进行逆向工程并在您的 python 代码中实现这些请求会简单得多(至少在这种情况下),完全避免了飞溅的需要。

    【讨论】:

    • Python selenium 完成了这项工作。谢谢!
    猜你喜欢
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    • 2019-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多