Git Product home page Git Product logo

scrapyjs's Introduction

Scrapyjs - Scrapy+Javascript integration

This library provides Scrapy-Javascript integration through two different mechanisms:

  • a Scrapy download handler
  • a Scrapy downloader middlware

You only need to use ONE of them, not both.

Requirements

  • python-gtk
  • python-webkit
  • python-jswebkit

Usage

Regardless of whether you are using the download handler or the downloader middleware variant, the usage is the same: those requests containing a "renderjs" key in request.meta will get download (and javascript rendered) through webkit instead of the Scrapy downloader.

Download handler setup

To enable the download handler add the following to your settings:

DOWNLOAD_HANDLERS = {
    'http': 'scrapyjs.dhandler.WebkitDownloadHandler',
    'https': 'scrapyjs.dhandler.WebkitDownloadHandler',
}

And make sure Scrapy uses the gtk2 reactor on twisted, for example by adding the following lines to scrapy/__init__.py:

from twisted.internet import gtk2reactor
gtk2reactor.install()

Handler pros:

  • it's asynchronous, and will merge with the main twisted reactor thread

Handler cons:

  • requires patching scrapy (to use gtk2 reactor), but this could be fixed by

making Scrapy reactor type configurable.

Downloader middlware setup

To enable the downloader middleware add the following to your settings.py:

DOWNLOADER_MIDDLEWARES = {
    'scrapyjs.middleware.WebkitDownloader': 1,
}

Middleware pros:

  • does not require patching scrapy (gtk reactor)

Middleware cons:

  • blocking API (it spawns a gtk loop for each request)

TODO

  • return WebView in response.meta, to support interaction and running custom javscript code from the spider
  • support custom request headers (User-Agent, Accept, etc)

scrapyjs's People

Contributors

pablohoffman avatar

Watchers

James Cloos avatar 童明 avatar

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.