使用python中的selenium在instagram上为人们解围

2024-05-20 14:10:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在开发一个instagram机器人,其中包括一些不关注的人。 它与selenium一起工作,方法是登录,单击“follow”,然后为每个用户单击unfollow按钮。问题是:当我尝试单击它时,此异常会发生:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button class="sqdOP  L3NKy _4pI4F   _8A5w5    " type="button">...</button> is not clickable at point (594, 155). Other element would receive the click: <span class="">...</span>


(Session info: chrome=79.0.3945.130)

这是我的密码:

    unfollow_buttons = driver.find_elements_by_css_selector('.sqdOP.L3NKy._8A5w5')

for button in unfollow_buttons:
    ui.WebDriverWait(driver, 5).until(
        EC.element_to_be_clickable((By.CSS_SELECTOR,
                                    '.sqdOP.L3NKy._8A5w5')))
    button.click()
    ui.WebDriverWait(driver, 2).until(
        EC.element_to_be_clickable((By.XPATH, '/html/body/div[5]/div/div/div[3]/button[1]')))
    driver.find_element_by_xpath('/html/body/div[5]/div/div/div[3]/button[1]').click() 

我知道另一个项目会收到点击,但我不知道它是什么项目。有人能帮我吗


Tags: divbydriverseleniumbuttonelementfindclass
1条回答
网友
1楼 · 发布于 2024-05-20 14:10:46

如果有人看到这一点,我会这样做:

    unfollow_buttons = driver.find_elements_by_css_selector('.sqdOP.L3NKy._8A5w5')

for button in unfollow_buttons:
    if button.text == "Following":  
        ui.WebDriverWait(driver, 5).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR,
                                        '.sqdOP.L3NKy._8A5w5')))
        actions = ActionChains(driver)
        actions.move_to_element(button).click().perform()
        ui.WebDriverWait(driver, 2).until(
            EC.element_to_be_clickable((By.XPATH,'/html/body/div[5]/div/div/div[3]/button[1]')))
        driver.find_element_by_xpath('/html/body/div[5]/div/div/div[3]/button[1]').click()  # UNFOLLOW CONFIRMATION
        time.sleep(1)

相关问题 更多 >