【问题标题】:Crawling website by selecting java script drop down menu in scrapy using splash通过使用splash在scrapy中选择java脚本下拉菜单来爬行网站
【发布时间】:2018-03-26 10:13:08
【问题描述】:

我正在尝试从 https://www.steelmint.com/ingot-prices-indian 获取每日价格。我已经使用splash设置了一个scrapy脚本,我需要选择不同日期的下拉菜单和废品价格作为数字。我只需要来自页面、日期和价格的两个数据。

我无法通过下拉菜单更改它的值,现在我可以找到任何指导它的教程。大多数处理表单处理但不起作用。

我使用 Splash 的 lua 脚本是:

    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

一旦页面被渲染,我很容易获得价值。新手来了提前致谢。

【问题讨论】:

    标签: scrapy web-crawler splash-screen scrapy-splash


    【解决方案1】:

    我认为你应该通过页面上的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
    

    【讨论】:

    • 运行顺畅。谢谢!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 1970-01-01
    • 2020-12-20
    • 1970-01-01
    • 1970-01-01
    • 2019-08-08
    • 1970-01-01
    相关资源
    最近更新 更多