使用splash在scrapy中选择java脚本下拉菜单来抓取网站
我想从你那里得到每天的价格。我已经使用splash设置了一个scrapy脚本,我需要选择不同日期的下拉菜单,并将scrapy price设置为数字。我只需要两个数据页,日期和价格 我无法获得下拉菜单“更改它”的值,现在可以找到任何指导它的教程。大多数处理表单处理,但不起作用 我使用Splash的lua脚本是:使用splash在scrapy中选择java脚本下拉菜单来抓取网站,scrapy,web-crawler,splash-screen,scrapy-splash,Scrapy,Web Crawler,Splash Screen,Scrapy Splash,我想从你那里得到每天的价格。我已经使用splash设置了一个scrapy脚本,我需要选择不同日期的下拉菜单,并将scrapy price设置为数字。我只需要两个数据页,日期和价格 我无法获得下拉菜单“更改它”的值,现在可以找到任何指导它的教程。大多数处理表单处理,但不起作用 我使用Splash的lua脚本是: function main(splash, args) local form = splash:select('form-control') local values =
function main(splash, args)
local form = splash:select('form-control')
local values = assert(form:form_values())
values.frmDt = "14"
values.frmMt = "March"
values.frmYr = "2018"
assert(form:fill(values))
assert(splash:go(args.url))
assert(splash:wait(0.5))
return {
html = splash:html(),``
png = splash:png(),
har = splash:har(),
}
end
一旦页面呈现出来,我就很容易获得价值。我是新手。提前感谢。我认为您应该通过页面上的splash运行javascript,这样更简单。请看以下工作示例:
function main(splash, args)
assert(splash:go(args.url))
assert(splash:runjs('document.getElementById("frmDt").value = "14"'))
assert(splash:runjs('document.getElementById("frmMt").value = "March"'))
assert(splash:runjs('document.getElementById("frmYr").value = "2018"'))
assert(splash:wait(0.5))
return {
html = splash:html(),``
png = splash:png(),
har = splash:har(),
}
end
工作顺利。谢谢