我们一直在使用scrapy-splash middleware通过运行在docker容器中的Splash javascript引擎传递抓取的HTML源代码。
如果我们想在爬行器中使用闪屏,我们需要配置几个required project settings并生成一个指定特定meta arguments的Request
yield Request(url, self.parse_result, meta={
'splash': {
'args': {
# set rendering arguments here
'html': 1,
'png': 1,
# 'url' is prefilled from request url
},
# optional parameters
'endpoint': 'render.json', # optional; default is render.json
'splash_url': '<url>', # overrides SPLASH_URL
'slot_policy': scrapyjs.SlotPolicy.PER_DOMAIN,
}
})这就像文档中描述的那样工作。但是,如何在Scrapy Shell中使用scrapy-splash呢
发布于 2016-02-12 17:54:21
只需在splash http api中包装您想要外壳的url。
所以你可能想要这样的东西:
scrapy shell 'http://localhost:8050/render.html?url=http://domain.com/page-with-javascript.html&timeout=10&wait=0.5'其中,localhost:port是运行启动服务的位置
url是你想抓取的网址,别忘了给它加上!
render.html是可能的http api端点之一,在本例中返回重新渲染的html页面。
超时的timeout时间(秒)
wait在读取/保存html之前等待javascript执行的时间。
发布于 2016-04-20 21:42:01
您可以在已配置的Scrapy项目中运行不带参数的scrapy shell,然后创建req = scrapy_splash.SplashRequest(url, ...)并调用fetch(req)。
发布于 2019-07-07 13:40:25
对于使用Docker Toolbox的windows用户:
invalid hostname:http错误。192.168.99.100.最后我得到了这个:
scrapy shell "http://192.168.99.100:8050/render.html?url="https://samplewebsite.com/category/banking-insurance-financial-services/""
https://stackoverflow.com/questions/35352423
复制相似问题