我正在尝试使用Scrapy Splash的render.png端点来截取以下网址的屏幕截图:
https://www.laithwaites.co.uk/product/Kilikanoon-Baroota-Shiraz-2014/66877在实践中,我使用python-requests发出请求,然而,即使当我在浏览器中进行测试时,它也会将cpu使用率推到100%以上(通过“top”测量),挂起很长一段时间,最终迫使Splash崩溃。我猜它快没内存了。
我尝试将maxrss从500增加到1500,但这没有帮助。我还尝试调整了render.png端点的等待/超时参数,但没有改变结果。
如何使用Splash截取此页面的屏幕截图?
发布于 2017-07-01 09:42:12
这似乎是JS引擎的一些问题。如果关闭JS,至少可以截图:
import requests
script = """
function main(splash)
local url = splash.args.url
splash.js_enabled = false
assert(splash:go(url))
return splash:png()
end
"""
resp = requests.post('http://localhost:8050/execute', json={
'lua_source': script,
'url': '<url>',
})如果您启用了详细日志记录(docker run -it -p8050:8050 scrapinghub/splash -v3),您可以看到在从cloudfront下载一些fetch.js文件后Splash挂起。它可能包含一些使Splash挂起的代码。您可以尝试仅过滤掉此文件(中止其下载),而不是禁用JS:
function main(splash)
local url = splash.args.url
splash:on_request(function (req)
if req.url:find('fetch.js') ~= nil then
req.abort()
end
end)
assert(splash:go(url))
return splash:png()
end上面的脚本适用于我。
https://stackoverflow.com/questions/44122662
复制相似问题