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
命令運行完畢後,就會成功安裝好此庫,後面會詳細介紹它的用法。