Splash是一個Javascript渲染服務。它是一個實現了HTTP API的輕量級瀏覽器,Splash是用Python實現的,同時使用Twisted和QT。Twisted(QT)用來讓服務具備異步處理能力,以發揮webkit的併發能力。javascript
爲了更加有效的製做網頁爬蟲,因爲目前不少的網頁經過javascript模式進行交互,簡單的爬取網頁模式沒法勝任javascript頁面的生成和ajax網頁的爬取,同時經過分析鏈接請求的方式來落實局部鏈接數據請求,相對比較複雜,尤爲是對帶有特定時間戳算法的頁面,分析難度較大,效率不高。而經過調用瀏覽器模擬頁面動做模式,須要使用瀏覽器,沒法實現異步和大規模爬取需求。鑑於上述理由Splash也就有了用武之地。一個頁面渲染服務器,返回渲染後的頁面,便於爬取,便於規模應用。html
安裝條件:java
Docker for Windows requires Windows 10 Pro or Enterprise version 10586, or Windows server 2016 RTM to runpython
首先點擊下面連接,從docker官網上下載windows下的docker進行安裝,不過請注意系統要求是**windows1064位 pro及以上版本或者教育版 linux
官網下載:https://store.docker.com/editions/community/docker-ce-desktop-windowsweb
安裝包下載完成後以管理員身份運行。ajax
查看信息:算法
#docker infodocker
#docker version網頁爬蟲
查看啓動的容器
在docker中下載安裝Splash鏡像,並安裝
#docker pull scrapinghub/splash
啓動splash服務
#啓動splash服務,並經過http,https,telnet提供服務 #一般通常使用http模式 ,能夠只啓動一個8050就好 #Splash 將運行在 0.0.0.0 at ports 8050 (http), 8051 (https) and 5023 (telnet). docker run -p 5023:5023 -p 8050:8050 -p 8051:8051 scrapinghub/splash
參考連接:https://www.jianshu.com/p/4052926bc12c
刪除原來的docker包,通常狀況下不用,保險起見,最好按流程走一下
$ sudo yum -y remove docker docker-common container-selinux
刪除docker的selinux 同上
$ sudo yum -y remove docker-selinux
使用yum 安裝yum-utils
$ sudo yum install -y yum-utils
增長docker源
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
查看docker源是否可用
$ sudo yum-config-manager --enable docker-ce-edge
enable 爲True就行
建立緩存
$ sudo yum makecache fast
使用yum安裝
docker如今分爲兩個版本 EE(企業版) CE(社區版),這裏咱們選擇CE版.
$ sudo yum install docker-ce
啓動docker
$ sudo systemctl start docker
啓動一個helloword
$ sudo docker run hello-world
這條命令會下載一個測試鏡像,並啓動一個容器,輸出hello world 並退出,若是正常說明docker安裝成功.
參考地址:https://www.cnblogs.com/colder219/p/6679255.html
一、配置splash服務(如下操做所有在settings.py):
1)添加splash服務器地址:
SPLASH_URL = 'http://localhost:8050'
2)將splash middleware添加到DOWNLOADER_MIDDLEWARE中:
DOWNLOADER_MIDDLEWARES = { 'scrapy_splash.SplashCookiesMiddleware': 723, 'scrapy_splash.SplashMiddleware': 725, 'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware': 810, }
3)Enable SplashDeduplicateArgsMiddleware:
SPIDER_MIDDLEWARES = { 'scrapy_splash.SplashDeduplicateArgsMiddleware': 100, }
4)Set a custom DUPEFILTER_CLASS:
DUPEFILTER_CLASS = 'scrapy_splash.SplashAwareDupeFilter'
5)a custom cache storage backend:
HTTPCACHE_STORAGE = 'scrapy_splash.SplashAwareFSCacheStorage'
案例:
import scrapy from scrapy_splash import SplashRequest class TbtaobaoSpider(scrapy.Spider): name = "tbtaobao" allowed_domains = ["www.taobao.com"] start_urls = ['https://s.taobao.com/search?q=堅果&s=880&sort=sale-desc'] def start_requests(self): for url in self.start_urls: # yield Request(url,dont_filter=True) yield SplashRequest(url, self.parse, args={'wait': 0.5}) def parse(self, response): print(response.text)