本文介绍了在www.instagram.com上接受Python/Selenium的Cookie错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 从时间导入睡眠从硒导入webdriver浏览器= webdriver.Firefox()browser.implicitly_wait(5)browser.get('https://www.instagram.com/')睡眠(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(<您的用户名>")password_input.send_keys(<您的密码>")login_button = browser.find_element_by_xpath("//button [@ type ='submit']")login_button.click()睡眠(5)browser.close() 

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

  ElementClickInterceptedException:消息:元素< button class ="sqdOP L3NKy y3zKF"type ="submit"在点(844,327)不可点击,因为另一个元素< div class ="piCib">掩盖它 

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

P.S.我已经在

解决方案

我也正在为此做些努力.该命令找到接受"消息.Cookie上的按钮弹出:

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

登录后提示另外2个弹出窗口:1保存登录信息,1允许浏览器上的通知."#not now"之后的行用同样的方式照顾他们

 从时间导入睡眠从硒导入webdriver浏览器= webdriver.Firefox()browser.implicitly_wait(5)browser.get('https://www.instagram.com/')睡眠(2)# 曲奇饼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(<<您的用户名>")password_input.send_keys(<您的密码>")login_button = browser.find_element_by_xpath("//button [@ type ='submit']")login_button.click()睡眠(3)# 现在不要save_login_info_button = browser.find_element_by_xpath("//button [text()='Not Now']'")save_login_info_button.click()睡眠(3)notification_button = browser.find_element_by_xpath("//button [text()='Not Now']'")notification_button.click()browser.close() 

I'm trying to, using Firefox, log into Instagram by using Python Selenium using the following code:

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()

Everytime I run it, it correctly opens a new web browser window, fills in the username and password entries but, in the end, I get the following error message:

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

I think it is due to the fact that there is a cookies acceptance pop-up that my code above is not dealing with. A screenshot with the automatically filled in username and password fields can be seen below. Does anyone know how to accept these cookies automatically?

P.S. I have tried the answer in Python/Selenium - Cant click' Accept cookies' button on www.instagram.com, but with no luck.

解决方案

I was working on this too and had a bit of struggle.This command finds the "Accept" button on the cookies pop up:

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

After the log in it prompts 2 more pop ups: 1 to save the log in informations, 1 to allow notifications on the browser. The lines after "#not now" take care of them in the same manner

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()

这篇关于在www.instagram.com上接受Python/Selenium的Cookie错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 03:55