芝麻HTTP:Scrapy-Splash的安裝,芝麻scrapy-splash

來源:互聯網
上載者:User

芝麻HTTP:Scrapy-Splash的安裝,芝麻scrapy-splash

Scrapy-Splash是一個Scrapy中支援JavaScript渲染的工具,本節來介紹它的安裝方式。

Scrapy-Splash的安裝分為兩部分。一個是Splash服務的安裝,具體是通過Docker,安裝之後,會啟動一個Splash服務,我們可以通過它的介面來實現JavaScript頁面的載入。另外一個是Scrapy-Splash的Python庫的安裝,安裝之後即可在Scrapy中使用Splash服務。

1. 相關連結
  • GitHub:https://github.com/scrapy-plugins/scrapy-splash
  • PyPI:https://pypi.python.org/pypi/scrapy-splash
  • 使用說明:https://github.com/scrapy-plugins/scrapy-splash#configuration
  • Splash官方文檔:http://splash.readthedocs.io
2. 安裝Splash

Scrapy-Splash會使用Splash的HTTP API進行頁面渲染,所以我們需要安裝Splash來提供渲染服務。這裡通過Docker安裝,在這之前請確保已經正確安裝好了Docker。

安裝命令如下:

docker run -p 8050:8050 scrapinghub/splash

安裝完成之後,會有類似的輸出結果:

2017-07-03 08:53:28+0000 [-] Log opened.2017-07-03 08:53:28.447291 [-] Splash version: 3.02017-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.22017-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: 10485762017-07-03 08:53:28.454258 [-] Can't bump open files limit2017-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-profiles2017-07-03 08:53:29.315445 [-] verbosity=12017-07-03 08:53:29.315629 [-] slots=502017-07-03 08:53:29.315712 [-] argument_cache_max_entries=5002017-07-03 08:53:29.316564 [-] Web UI: enabled, Lua: enabled (sandbox: enabled)2017-07-03 08:53:29.317614 [-] Site starting on 80502017-07-03 08:53:29.317801 [-] Starting factory <twisted.web.server.Site object at 0x7ffaa4a98cf8>

這樣就證明Splash已經在8050連接埠上運行了。這時我們開啟http://localhost:8050,即可看到Splash的首頁,1-80所示。

                                                                             圖1 運行頁面

當然,Splash也可以直接安裝在遠程伺服器上。我們在伺服器上以守護態運行Splash即可,命令如下:

docker run -d -p 8050:8050 scrapinghub/splash

這裡多了-d參數,它代表將Docker容器以守護態運行,這樣在中斷遠程伺服器串連後,不會終止Splash服務的運行。

3. Scrapy-Splash的安裝

成功安裝Splash之後,接下來再來安裝其Python庫,命令如下:

pip3 install scrapy-splash

命令運行完畢後,就會成功安裝好此庫。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.