【问题标题】:How to handle new tab opening with Splash?如何使用 Splash 处理新标签打开?
【发布时间】:2018-03-21 18:24:10
【问题描述】:
我正在抓取具有非常烦人的链接(<a> HTML 标记)的网站 - 它会在点击时打开小弹出式表单,提交后会打开带有 URL 的新浏览器选项卡(并将焦点切换到它)我需要,并且还将旧标签重定向到另一个页面。
成功提交弹出表单很容易,但我不知道如何获取这个新标签的 URL。
正如文档所说,Splash 只能使用一个选项卡,所以不可能做到这一点吗?
【问题讨论】:
标签:
scrapy-splash
splash-js-render
【解决方案1】:
作为 Splash 的开发者 comments this GitHub issue 未实现此功能。
但我在同一问题上发布了my solution 到这个问题。
示例:
function main(splash, args)
assert(splash:go(args.url)) -- execute JS code below only after loading the page
splash:runjs("var newTabURL")
splash:runjs("newTabURL = null") -- sometimes JS can't find variable without this line
splash:runjs("window.open = function(url){newTabURL = url}")
-- actions which open the new tab
local new_tab_url = splash:evaljs("newTabURL")
-- other actions
end