0

I want to use Python and Splash to select the 'Ich stimme zu' button with XPATH and then click.

I can't use the CSS class because it has a dynamic name.

URL: https://consent.google.com/m?continue=https://www.google.com/maps/search/Berlin%2Brestaurant/&gl=DE&m=0&pc=m&hl=de&src=1

Can someone help me here please?

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
  • Not tested: `xpath("//span[contains(text(), 'Ich stimme zu')]")` ? `xpath("//button[span[contains(text(), 'Ich stimme zu')]]")` ? `xpath("//button[2]")` ? – furas Feb 24 '22 at 23:03

1 Answers1

0

It turns out that I can click on the button absolutely fine with CSS - I have tested it on the console.

It seems you're trying to integrate the script with scrapy-splash, turns out that the message you get does not appear on the splash console.Perhaps you were trying it and there was no button because you did not realise this?

Anyways - here's what worked for me in the console, I have updated it within the lua script:

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
tesla john
  • 310
  • 1
  • 2
  • 9