'Youtube cookies auto accept with puppeteer
Im trying to find something can automatically accept or delete youtube cookies with puppeteer when i load "youtube.com"
Example of popup you can get in private navigation
I don't know how to get the selector of this custom button "Accept".
Solution 1:[1]
I had the same issue but FIRST you should chaneg the PAGE LANG to 'US-en' then try this code:
Dim iframeElementConsent = Await page.QuerySelectorAsync("#lightbox")
If (iframeElementConsent IsNot Nothing) Then
Await page.EvaluateExpressionAsync("window.scrollBy(0, window.innerHeight)")
Thread.Sleep(random.[Next](3000, 5000))
Dim Frame = Await iframeElementConsent.ContentFrameAsync()
Await page.ClickAsync("[aria-label='Agree to the use of cookies and other data for the purposes described']")
End If
OR you can inspect the elements and change the ARIA LAbel to your desired text.
IF THAT doesn't work you can still install to your browser 'I dont care cookies' extension and call it in browser Arguments like this:
browser = Await Extra.LaunchAsync(New LaunchOptions With {
.ExecutablePath = chromePath,
.IgnoreHTTPSErrors = False,
.DefaultViewport = Nothing,
.IgnoredDefaultArgs = New String() {"--disable-extensions", "--enable-automation"},
.Args = New String() {"--proxy-server=" & _proxy,
"--mute-audio",
"--no-sandbox",
"--start-maximized",
"--disable-setuid-sandbox",
"--disable-dev-shm-usage",
"--disable-accelerated-2d-canvas",
"--disable-2d-canvas-clip-aa",
"--no-first-run",
"--no-zygote",
"--disable-gpu",
"--load-extension=C:\Users\" & pcUser & "\AppData\Local\BraveSoftware\Brave-Browser\User\Default\Extensions\fihnjjcciajhdojfnbdddfaoknhalnja\3.3.8_0"},
.Headless = headless
})
PS: In this example I use Bravebrowser which is better to load YouTube as Chrome btw..
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 | DharmanBot |