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

查看:65
本文介绍了Python/硒-不能在www.instagram.com上单击“接受cookie"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python硒登录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/硒-不能在www.instagram.com上单击“接受cookie"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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