我尝试使用python selenium登录instagram。但我必须接受cookie才能继续。
这是我的密码
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)
问题是,当它点击接受按钮时,它什么也不做。有什么想法吗
4条答案
按热度按时间aamkag611#
应单击accept the login及其后面的两个元素。只要等到元素变成可点击的,然后点击它。
进口
uhry853o2#
试试这个:
我在这里发布了我的解决方案:在www.example.com上使用Python/Selenium接受cookie错误www.instagram.com
j8ag8udp3#
你可以使用这个代码:
o2rvlv0m4#
我找到了一种方法,通过选择相应文本的按钮。