Coder Social home page Coder Social logo

Comments (3)

ramsayleung avatar ramsayleung commented on May 30, 2024

可否描述一下你的问题呢,你只是发一个标题,我真的不知道你想要做什么?

from jd_spider.

ricksanche2 avatar ricksanche2 commented on May 30, 2024

安装scrapy-splash:

$ pip install scrapy-splash

爬取前开启splash:

$ docker run -p 8050:8050 scrapinghub/splash

settings.py中:
加入splash服务器地址 SPLASH_URL = 'http://127.0.0.1:8050'
并启用splash中间件(也就是将

DOWNLOADER_MIDDLEWARES = {
...
}

变为以下:)

DOWNLOADER_MIDDLEWARES = {
    'scrapy_splash.SplashCookiesMiddleware': 723,
    'scrapy_splash.SplashMiddleware': 725,
    'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware': 810,
}

并且将SplashDeduplicateArgsMiddleware加入SPIDER_MIDDLEWARES

SPIDER_MIDDLEWARES = {
    'scrapy_splash.SplashDeduplicateArgsMiddleware': 100,
}

在spider.py中:
yield Request(url, self.parse_result)改为

yield SplashRequest(url, self.parse_result,
    args={
        # optional; parameters passed to Splash HTTP API
        'wait': 0.5,

        # 'url' is prefilled from request url
        # 'http_method' is set to 'POST' for POST requests
        # 'body' is set to request body for POST requests
    },
    endpoint='render.json', # optional; default is render.html
    splash_url='<url>',     # optional; overrides SPLASH_URL
    slot_policy=scrapy_splash.SlotPolicy.PER_DOMAIN,  # optional
)

上面不懂的话,改为

yield SplashRequest(url, self.parse_result,
    args={
        'wait': 0.5,#结果不全或者没结果的话,加大这个值
    }
)

就能在http://你的服务器外网ip(如果在本机部署的话就是127.0.0.1):8050初步看到结果了
其余蜘蛛代码简单情况下可以不变

from jd_spider.

ramsayleung avatar ramsayleung commented on May 30, 2024

你能否表述一下你的问题呢?使用 scrapy-splash 干什么,解决了什么问题,和现在这个项目有什么相关的东西?

from jd_spider.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.