Python,使用 Splash 选择 XPATH 并点击按钮

我想使用 Python 和 Splash 通过 XPATH 选择 'Ich stimme zu' 按钮,然后点击。

无法使用 CSS 类,因为它具有动态名称。

URL: https://consent.google.com/m?continue=https://www.google.com/maps/search/Berlin%2Brestaurant/\u0026gl=DE\u0026m=0\u0026pc=m\u0026hl=de\u0026src=1

请有人帮我吗?

function main(splash)
      local url = splash.args.url
      assert(splash:go(url))
      assert(splash:wait(0.5))

      bounds = selector:xpath("/html/body/c-wiz/div/div/div/div[2]/div[1]/div[4]/form/div/div").click()
        return {
        html = splash:html(),
        png = splash:png(),
        href=href,
      }
end

原文链接 https://stackoverflow.com/questions/71258810

点赞
stackoverflow用户18248287
stackoverflow用户18248287

事实证明,我可以使用 CSS 完全正常地点击按钮——我已在控制台上进行了测试。

看起来你正在尝试将脚本与 scrapy-splash 集成,结果你收到的消息在 splash 控制台上没有出现。也许你试过了,但没有出现按钮,因为你没有意识到这点?

无论如何——这是控制台中对我有效的操作,我已经在 lua 脚本中进行了更新:

function main(splash, args)
  assert(splash:go(args.url))
  local click_on = splash:jsfunc([[
    function(){
    document.querySelector("button[aria-label='Consent to the use of cookies and other data for the purposes described']").click()
  }
    ]])
  splash:wait(0.5)
  click_on()
  splash:wait(3)
  return {
    html = splash:html(),
    png = splash:png(),
    har = splash:har(),
  }
end
2022-02-25 16:11:24