【发布时间】:2021-01-05 08:37:11
【问题描述】:
这是我第一次使用 splash 来抓取网站。我需要告诉 splash 单击一个按钮,以便在浏览器上加载其他元素。这种情况无限进行。然后我想让splash返回HTML代码,这样我就可以用我的蜘蛛刮掉它。加载按钮没有href,所以我不能使用分页。因此,我尝试编写一个启动脚本来做到这一点。但是当我用 splash 运行脚本时,似乎“btn”部分在返回的 HTML 中没有任何作用(每次只返回第一页的 HTML。)
这是我写的启动脚本:
function main(splash,args)
local function wait_for(it)
item=splash:select(it)
while not item:visible() do
splash:wait(0.25)
item=splash:select(it)
return item
end
end
splash.private_mode_enabled=false
local head={'User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome'}
assert(splash:go(args.url,headers=head))
selector='.undefined.btn.small-Font'
wait_for(selector):mouse_click()
selector='.rtl.custom-container.pb-5'
wait_for(selector):mouse_click()
return splash:html()
end
谁能帮我理解我如何告诉splash“当“加载按钮”存在时,按下它,然后立即返回整个HTML”?
顺便说一下,这是我要抓取的非英文 URL: http://namlik.me/channels
非常感谢!!
---编辑---
这是我在响应页面上遇到的错误:
{
"error": 400,
"type": "ScriptError",
"description": "Error happened while executing Lua script",
"info": {
"source": "[string \"function main(splash,args)\r...\"]",
"line_number": 14,
"error": "')' expected near '='",
"type": "LUA_INIT_ERROR",
"message": "[string \"function main(splash,args)\r...\"]:14: ')' expected near '='"
}
}
【问题讨论】:
标签: web-scraping lua scrapy-splash