它也可以正常工作docker-toolbox
。只需遵循类似的过程,并确保您提供您可以通过以下方式访问的 docker 全局 url:
docker-machine ip default
如果您不知道该过程,这是一种方法,您可以使用scrapy-splash
:
在 docker 上运行启动
# Install Docker 'http://docker.io/'
# Pull the image:
$ sudo docker pull scrapinghub/splash
# Start the container:
$ sudo docker run -p 8050:8050 -p 5023:5023 scrapinghub/splash
# Splash is now available at 192.168.99.100 at ports 8050 (http) and 5023 (telnet).
插入scrapy.setting
# splash for scripting or js dependent web-page
# Access docker-machine ip=> docker-machine ip default
SPLASH_URL = '<docker-hosted machine ip:port>' # docker url
#SPLASH_URL = 'http://192.168.99.100:8050' # docker url
DOWNLOADER_MIDDLEWARES = {
'scrapy_splash.SplashCookiesMiddleware': 723,
'scrapy_splash.SplashMiddleware': 725,
'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware': 810,
}
SPIDER_MIDDLEWARES = {
'scrapy_splash.SplashDeduplicateArgsMiddleware': 100,
}
DUPEFILTER_CLASS = 'scrapy_splash.SplashAwareDupeFilter'
解析 url .. 在生成 url 之前添加一个启动元数据
response.meta['splash'] = {'args': { 'html': 1, 'png': 1}, 'endpoint': 'render.json'}
yield scrapy.Request(response.url, callback=self.parse_page, meta=response.meta)
有关更多详细信息,请查看此文档:
javascript-in-scrapy-with-splash
splash-through-http-api