'Python, Splash select XPATH and click button
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.
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
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | tesla john |
