在 python 中使用硒取消关注 Instagram 上的人

Unfollowing people on instagram with selenium in python

我正在开发一个涉及取消关注的人的 Instagram 机器人。 它通过登录与 selenium 一起工作,单击 "Following",然后对于每个用户,它应该单击取消关注按钮。问题是:当我尝试单击它时,出现此异常:

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

我知道另一个项目会收到点击,但我不明白它是什么项目。有没有人可以帮我解决这个问题?

如果有人看到这个,我用这种方式解决了这个问题:

    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)