一、利用pip安装scrapy-splash库:
pip install scrapy-splash
二、安装docker, 安装好后运行docker(参考docker笔记) https://blog.csdn.net/u011394598/article/details/83060982
三、拉取镜像(pull the image):
docker pull scrapinghub/splash
四、用docker运行scrapinghub/splash:
docker run -p 8050:8050 scrapinghub/splash
五、在爬虫的settings中配置
1、设置下载中间件:
DOWNLOADER_MIDDLEWARES = {
'scrapy_splash.SplashCookiesMiddleware': 723,
'scrapy_splash.SplashMiddleware': 725,
'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware': 810,
}
2.设置爬虫中间件:
SPIDER_MIDDLEWARES = {
'scrapy_splash.SplashDeduplicateArgsMiddleware': 100,
}
使用splash解析,要在配置文件中设置:
SPLASH_URL = 'http://127.0.0.1:8050/'
4.配置消息队列所使用的过滤类:
DUPEFILTER_CLASS = 'scrapy_splash.SplashAwareDupeFilter'
配置消息队列需要使用的类:
HTTPCACHE_STORAGE = 'scrapy_splash.SplashAwareFSCacheStorage'