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"按钮
基础教程推荐
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
