ale*_*cxe 16 scrapy web-scraping scrapy-shell scrapy-splash splash-js-render
我们一直在使用scrapy-splash中间件通过在Splashdocker容器内运行的javascript引擎传递已删除的HTML源代码.
如果我们想在spider中使用Splash,我们配置几个必需的项目设置并产生一个Request指定特定的meta参数:
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,
}
})
Run Code Online (Sandbox Code Playgroud)
这有助于记录.但是,我们如何scrapy-splash在Scrapy Shell中使用?
Gra*_*rus 24
只需将你想要shell的url包装到splash http api中.
所以你会想要这样的东西:
scrapy shell 'http://localhost:8050/render.html?url=http://domain.com/page-with-javascript.html&timeout=10&wait=0.5'
Run Code Online (Sandbox Code Playgroud)
这里localhost:port是你的飞溅服务运行的位置
url是要爬网和不要忘记网址urlquote吧!
render.html是一个可能的http api端点,在这种情况下返回redered html页面的
timeout时间以秒为
wait单位,等待javascript在读取/保存html之前执行的超时时间(以秒为单位).
Mik*_*bov 18
您可以scrapy shell在已配置的Scrapy项目中运行不带参数,然后创建req = scrapy_splash.SplashRequest(url, ...)并调用fetch(req).
| 归档时间: |
|
| 查看次数: |
7529 次 |
| 最近记录: |