如何解决splash:set_viewport_full() 在 localhost 中工作正常,而当我运行 scrapy 代码时,它只保存了一半的图像
我是 Scrapy-Splash 的新手,我想截取整个网页的屏幕截图。例如“https://stackoverflow.com/”。 在 lua 脚本中,我添加了以下代码-
function main(splash,args)
assert(splash:go(args.url))
assert(splash:wait(0.5))
splash:set_viewport_full()
return {
html = splash:html(),png = splash:png(),har = splash:har(),}
end
我可以在 Splash loaclhost 中看到完整的网页截图。Here is the image. I have not downloaded it. I want to just show that it works fine here.
而我想直接将其保存在本地。我想通过scrapy将它们保存在本地,而不是从Splash localhost手动下载图像。所以我在 Scrapy-Splash-
中编写了以下代码class TestSpider(scrapy.Spider):
name = 'test'
def start_requests(self):
url='https://stackoverflow.com/'
splash_args = {
'html': 1,'png': 1,'wait':0.5
}
yield SplashRequest(url,self.parse_result,endpoint='render.json',args=splash_args)
def parse_result(self,response):
imgdata = base64.b64decode(response.data['png'])
filename = 'stackoverflow.png'
with open(filename,'wb') as f:
f.write(imgdata)
下载此图像时,我看到图像被裁剪掉了。 Here is the screenshot of the cropped image after running the above code。
当我运行此代码时,我获得了 200 成功,如下所示 - 这意味着代码是通过 splash localhost 运行的。
Crawled (200) <GET https://stackoverflow.com/ via http://localhost:8050/render.json> (referer: None)
我附上了两张图片。我再次成为 Scrapy-Splash 的新手。请帮我找到解决此问题的方法?谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。