Scrapy-Splash是一个Scrapy中支持JavaScript渲染的工具,本节来介绍它的安装方式。python
Scrapy-Splash的安装分为两部分。一个是Splash服务的安装,具体是经过Docker,安装以后,会启动一个Splash服务,咱们能够经过它的接口来实现JavaScript页面的加载。另一个是Scrapy-Splash的Python库的安装,安装以后便可在Scrapy中使用Splash服务。git
Scrapy-Splash会使用Splash的HTTP API进行页面渲染,因此咱们须要安装Splash来提供渲染服务。这里经过Docker安装,在这以前请确保已经正确安装好了Docker。github
安装命令以下:web
docker run -p 8050:8050 scrapinghub/splash
安装完成以后,会有相似的输出结果:docker
2017-07-03 08:53:28+0000 [-] Log opened. 2017-07-03 08:53:28.447291 [-] Splash version: 3.0 2017-07-03 08:53:28.452698 [-] Qt 5.9.1, PyQt 5.9, WebKit 602.1, sip 4.19.3, Twisted 16.1.1, Lua 5.2 2017-07-03 08:53:28.453120 [-] Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] 2017-07-03 08:53:28.453676 [-] Open files limit: 1048576 2017-07-03 08:53:28.454258 [-] Can't bump open files limit 2017-07-03 08:53:28.571306 [-] Xvfb is started: ['Xvfb', ':1599197258', '-screen', '0', '1024x768x24', '-nolisten', 'tcp'] QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root' 2017-07-03 08:53:29.041973 [-] proxy profiles support is enabled, proxy profiles path: /etc/splash/proxy-profiles 2017-07-03 08:53:29.315445 [-] verbosity=1 2017-07-03 08:53:29.315629 [-] slots=50 2017-07-03 08:53:29.315712 [-] argument_cache_max_entries=500 2017-07-03 08:53:29.316564 [-] Web UI: enabled, Lua: enabled (sandbox: enabled) 2017-07-03 08:53:29.317614 [-] Site starting on 8050 2017-07-03 08:53:29.317801 [-] Starting factory <twisted.web.server.Site object at 0x7ffaa4a98cf8>
这样就证实Splash已经在8050端口上运行了。这时咱们打开http://localhost:8050,便可看到Splash的主页,如图1所示。api
图1 运行页面服务器
固然,Splash也能够直接安装在远程服务器上。咱们在服务器上以守护态运行Splash便可,命令以下:scrapy
docker run -d -p 8050:8050 scrapinghub/splash
这里多了-d
参数,它表明将Docker容器以守护态运行,这样在中断远程服务器链接后,不会终止Splash服务的运行。tcp
成功安装Splash以后,接下来再来安装其Python库,命令以下:工具
pip3 install scrapy-splash
命令运行完毕后,就会成功安装好此库,后面会详细介绍它的用法。