Python/Selenium - Cant click#39; Accept cookies#39; button on www.instagram.com(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"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python/Selenium - 无法单击 www.instagram.com 上的“接受 cookie"按钮
基础教程推荐
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
