Python/Selenium - 无法单击 www.instagram.com 上的“接受 cookie"按钮

问题描述

我正在尝试使用 python selenium 登录 instagram.但我必须接受 cookie 才能继续.

Im trying to login on instagram using python selenium. But i have to Accept the cookies in order to continue.

这是我的代码

class InstaBot:
    def __init__(self, username, pw):
        self.driver = webdriver.Chrome()
        self.driver.get('https://www.instagram.com/')
        sleep(2)
 #this is the code that im trying to use, so to click the accept button 
self.driver.find_element_by_xpath("/html/body/div[2]/div/div/div/div[2]/button[1]").click() 
        self.driver.find_element_by_xpath("//input[@name="username"]")
            .send_keys(username)
        self.driver.find_element_by_xpath("//input[@name="password"]")
            .send_keys(pw)
        self.driver.find_element_by_xpath("//a[contains(text(), 'Log in')]")
            .click()
        sleep(4)

问题是当它点击接受按钮时它什么也不做.有什么想法吗?

The problem is that when it gets to click the accept button it does nothing. Any ideas?


解决方案

试试这个:

self.driver.find_element_by_xpath("//button[text()='Accept']").click()

我在这里发布了我的解决方案:在 www.instagram.com 上使用 Python/Selenium 接受 cookie 错误

I posted my solution here: Accepting cookies error with Python/Selenium on www.instagram.com

相关文章