Web scraping 刮擦的外壳和刮擦的飞溅物
我们一直在使用它通过运行在docker容器中的Web scraping 刮擦的外壳和刮擦的飞溅物,web-scraping,scrapy,scrapy-splash,scrapy-shell,splash-js-render,Web Scraping,Scrapy,Scrapy Splash,Scrapy Shell,Splash Js Render,我们一直在使用它通过运行在docker容器中的Splashjavascript引擎传递刮取的HTML源代码 如果我们想在spider中使用Splash,我们会配置几个,并生成一个请求指定特定的: yield请求(url、self.parse\u结果、meta={ “飞溅”:{ “args”:{ #在此处设置渲染参数 “html”:1, "png":1,, #“url”是从请求url中预先填充的 }, #可选参数 '端点':'render.json',#可选;默认值为render.json 'sp
Splash
javascript引擎传递刮取的HTML源代码
如果我们想在spider中使用Splash,我们会配置几个,并生成一个请求
指定特定的:
yield请求(url、self.parse\u结果、meta={
“飞溅”:{
“args”:{
#在此处设置渲染参数
“html”:1,
"png":1,,
#“url”是从请求url中预先填充的
},
#可选参数
'端点':'render.json',#可选;默认值为render.json
'splash_url':'',覆盖splash_url
“插槽策略”:scrapyjs.SlotPolicy.PER\u域,
}
})
这是有据可查的。但是,我们如何在内部使用
scrapy splash
?只需将您想要shell的url包装起来即可
所以你会想要一些类似的东西:
scrapy shell 'http://localhost:8050/render.html?url=http://domain.com/page-with-javascript.html&timeout=10&wait=0.5'
其中localhost:port
是splash服务运行的位置url
是您想要爬网的url,别忘了urlquote它render.html
是可能的http api端点之一,在本例中返回重新设计的html页面超时
超时时间(秒)wait
在读取/保存html之前等待javascript执行的时间(秒)。您可以在配置的scrapy项目中运行scrapy shell
,无需参数,然后创建req=scrapy\u splash.SplashRequest(url,…)
并调用fetch(req)
对于使用Docker工具箱的windows用户:
无效主机名:http
错误scrapy shell”http://192.168.99.100:8050/render.html?url="https://samplewebsite.com/category/banking-insurance-financial-services/“”
您可能可以创建一个bash别名,以使其更方便。确实,没有默认的\u请求\u元,就像有一个。关于默认情况下通过中间件启用Splash,有公开讨论(请参阅)。另一个选项是将scrapy splash mdw子类化,并在其中强制设置。欢迎提出意见
scrapy shell 'http://localhost:8050/render.html?url=http://domain.com/page-with-javascript.html&timeout=10&wait=0.5'