0

我正在尝试使用我目前正在编码的“instagram bot”登录 Instagram。我已经通过了登录屏幕,但我对以下弹出窗口有疑问)说 https://i.stack.imgur.com/OMA6h.png

from selenium import webdriver
from time import sleep

path="C:\Program Files (x86)\chromedriver.exe"


class instabot:

def __init__(self,username,pw):
#def __init__(self):
    self.driver=webdriver.Chrome(path)
    self.driver.get("https://www.instagram.com")``

    sleep(2)
    #to give input to username
    self.driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[1]/div/label/input').send_keys(username)
    self.driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[2]/div/label/input').send_keys(pw)
    self.driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[3]').click()
    

    sleep(1500)
    
4

2 回答 2

1

只需执行以下操作,等待元素可单击,然后单击。

WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Not Now']"))).click()

进口

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
于 2020-10-11T06:03:42.970 回答
0

登录后,您必须找到“不是现在”按钮,然后单击它。我不确定您对浏览器开发工具和 DOM 的熟悉程度。您必须寻找一个idclass或者您可以使用xpath您在登录时所做的那样。

有很多方法可以找到和识别此按钮。当你找到它时,调用该.click()函数。

于 2020-10-10T14:31:30.433 回答