如何在lua中修复此代码以在scrapy启动项目中启动?

时间:2019-04-22 12:21:07

标签: lua scrapy splash scrapy-splash

我有一个[link](https://www.psychologytoday.com/us/therapists/35801),我想为其提交联系表格。我知道我必须使用3rd party服务,因为有一个Recaptcha,但是我似乎无法加载脚本。我不断收到表格错误,而不是单击按钮

我已经完成了for循环并单击鼠标,但是它不起作用。我使用的选择器是“ div.result-btn-email按钮”,它可以在chrome开发工具中使用

function main(splash, args)

  local function submit_forms()
    local btns = splash:select_all('div.result-btn-email button')
    if #btns == 0 then
      error('no elements found')
    end
    for _, btn in ipairs(btns) do
      print(btn, 'found button')
      splash:wait(1)
      btn:mouse_click()
      print(btn, ' found buttn')
    end
  end

  assert(splash:go(args.url))
  assert(splash:wait(0.5))
  submit_forms()

  return {
    html = splash:html(),
    png = splash:png(),
    har = splash:har(),
  }
end

我知道这是不完整的代码,但是仍然无法正常工作,我一直收到错误消息:

{
    "type": "ScriptError",
    "info": {
        "type": "LUA_ERROR",
        "message": "Lua error: [string \"function main(splash, args)\r...\"]:11: JsError({'js_error': \"TypeError: undefined is not an object (evaluating 'rect.left')\", 'type': 'JS_ERROR', 'message': 'JS error: \"TypeError: undefined is not an object (evaluating \\'rect.left\\')\"', 'js_error_message': \"undefined is not an object (evaluating 'rect.left')\", 'js_error_type': 'TypeError'},)",
        "line_number": 11,
        "error": "JsError({'js_error': \"TypeError: undefined is not an object (evaluating 'rect.left')\", 'type': 'JS_ERROR', 'message': 'JS error: \"TypeError: undefined is not an object (evaluating \\'rect.left\\')\"', 'js_error_message': \"undefined is not an object (evaluating 'rect.left')\", 'js_error_type': 'TypeError'},)",
        "source": "[string \"function main(splash, args)\r...\"]"
    },
    "error": 400,
    "description": "Error happened while executing Lua script"
}

我是lua的新手,很乐意为学习lua提供一些帮助和资源

0 个答案:

没有答案