本文介紹了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"按鈕的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!