https://github.com/scrapy-plugins/scrapy-splash#responses
). 要访问google.com的PNG数据,您应该执行以下操作:
import base64
# ...
def parse_result(self, response):
img = base64.b64decode(response.data["www.google.com"])
# ...
{"<url>": "<base64 png data>"}
映射,而不是数组。
treat.as_array
:
treat = require('treat')
function main(splash, args)
splash.set_viewport_size(800, 600)
splash.set_user_agent('Splash bot')
local example_urls = {"www.google.com", "www.bbc.co.uk", "scrapinghub.com"}
local urls = args.urls or example_urls
local results = {}
for i, url in ipairs(urls) do
local ok, reason = splash:go("http://" .. url)
if ok then
splash:wait(0.2)
results[i] = splash:png()
end
end
return treat.as_array(results)
end
然后您可以访问以下数据:
import base64
# ...
def parse_result(self, response):
img = base64.b64decode(response.data[0])
# ...