栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python > python爬虫

Python3爬虫利器:Scrapy-Splash的安装

python爬虫 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python3爬虫利器: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.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 

这样就证明Splash已经在8050端口上运行了。这时我们打开http://localhost:8050,即可看到Splash的主页,如图1-80所示。

图1-80 运行页面

当然,Splash也可以直接安装在远程服务器上。我们在服务器上以守护态运行Splash即可,命令如下:

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

这里多了-d参数,它代表将Docker容器以守护态运行,这样在中断远程服务器连接后,不会终止Splash服务的运行。

3. Scrapy-Splash的安装

成功安装Splash之后,接下来再来安装其Python库,命令如下:

pip3 install scrapy-splash

命令运行完毕后,就会成功安装好此库,后面会详细介绍它的用法。

python学习网,大量的免费python视频教程,欢迎在线学习!

本文转自:https://cuiqingcai.com/5428.html

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/12603.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号