Python/Selenium - 无法单击 www.instagram.com 上的“接受 cookie"按钮 [英] Python/Selenium - Cant click' Accept cookies' button on www.instagram.com

查看:31
本文介绍了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

这篇关于Python/Selenium - 无法单击 www.instagram.com 上的“接受 cookie"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆