scrapy+splash 的使用

使用splash需要安装docker,我这里使用的是ubuntu20.04.

1、安装docker

sudo apt install docker.io
sudo docker pull scrapinghub/splash

1、开放端口

安装完成之后需要开放本机的8050和8051端口,不然运行不了爬虫。

sudo docker run -p 8050:8050 -p 8051:8051 scrapinghub/splash

3、在爬虫中使用splash

3.1 安装splash

pip3 install scrapy-splash

3.2 在scrapy的setting.py文件中添加以下内容
在这里插入图片描述

# splash server url address
SPLASH_URL="http://localhost:8050"

# open splash's two downloader and adjust the sort of HttpCompressionMiddleware
DOWNLOADER_MIDDLEWARES={
    'scrapy_splash.SplashCookiesMiddleware':723,
    'scrapy_splash.SplashMiddleware':725,
    'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware':810,
}

# setting the filter
DUPEFILTER_CLASS='scrapy_splash.SplashAwareDupeFilter'

# to support cache_args (could choose)
#SPIDER_MIDDLEWARES={
#    'scrapy_splash.SplashDeduplicateArgsMiddlewares':100,
#}

3.3 编写spider
以下是我的各个文件(只修改过setting.py和quotes.py)
在这里插入图片描述
3.4 运行爬虫

scrapy crawl quotes -o quotes.csv

查看quote.csv

cat -n quotes.csv

4、运行结果

在这里插入图片描述
在这里插入图片描述

5、补充

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值