Warm tip: This article is reproduced from serverfault.com, please click

其他-在www.instagram.com上接受Python / Selenium的Cookie错误

(其他 - Accepting cookies error with Python/Selenium on www.instagram.com)

发布于 2020-11-15 16:48:56

我正在尝试使用Firefox,使用以下代码通过Python Selenium登录Instagram:

from time import sleep
from selenium import webdriver

browser = webdriver.Firefox()
browser.implicitly_wait(5)

browser.get('https://www.instagram.com/')
sleep(2)

username_input = browser.find_element_by_css_selector("input[name='username']")
password_input = browser.find_element_by_css_selector("input[name='password']")

username_input.send_keys("<your username>")
password_input.send_keys("<your password>")

login_button = browser.find_element_by_xpath("//button[@type='submit']")
login_button.click()

sleep(5)

browser.close()

每次我运行它时,它都会正确打开一个新的Web浏览器窗口,并填写用户名和密码条目,但是最后,我收到以下错误消息:

ElementClickInterceptedException: Message: Element <button class="sqdOP  L3NKy   y3zKF     " type="submit"> is not clickable at point (844,327) because another element <div class="piCib"> obscures it

我认为是由于存在我上面的代码未处理的cookie接受弹出窗口。屏幕快照包含自动填写的用户名和密码字段,如下所示。有谁知道如何自动接受这些cookie?

言:我已经尝试了Python / Selenium中的答案-不能在www.instagram.com上单击“接受cookie”按钮,但是没有运气。

饼干弹出

谢谢!

马里奥安萨斯

Questioner
Marioanzas
Viewed
11
U_double_G 2020-11-29 21:43:54

我也正在为此做一些努力。此命令在弹出的cookie上找到“接受”按钮:

find_element_by_xpath("//button[text()='Accept']")

登录后提示另外2个弹出窗口:1保存日志信息,1允许浏览器上的通知。“ #not now”之后的行以相同的方式处理它们

from time import sleep
from selenium import webdriver

browser = webdriver.Firefox()
browser.implicitly_wait(5)

browser.get('https://www.instagram.com/')

sleep(2)
# cookie 
cookie_button = browser.find_element_by_xpath("//button[text()='Accept']")
cookie_button.click()

username_input = browser.find_element_by_css_selector("input[name='username']")
password_input = browser.find_element_by_css_selector("input[name='password']")

username_input.send_keys("<your username>")
password_input.send_keys("<your password>")

login_button = browser.find_element_by_xpath("//button[@type='submit']")
login_button.click()

sleep(3)
# not now
save_login_info_button= browser.find_element_by_xpath("//button[text()='Not Now']")
save_login_info_button.click()
sleep(3)
notification_button= browser.find_element_by_xpath("//button[text()='Not Now']")
notification_button.click()

browser.close()