You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Python的Selenium滚动Instagram Bot中的子弹窗

Fixing Instagram Modal Scroll Issues with Selenium in Python

Hey there! I’ve dealt with this exact problem when building Instagram bots before—those modals (like follower/following lists, message threads) have their own independent scroll containers, so scrolling the main window won’t touch them. Let’s break down how to fix it:

Step 1: Locate the Modal’s Scrollable Container

First, you need to identify the actual DOM element that handles scrolling for the modal. On Instagram, these modals typically use a <div> with a specific class (it might change over time, but right now common ones are _aano for follower lists).

To find it:

  • Open your browser’s dev tools (F12), go to the Elements tab.
  • Right-click inside the scrollable area of the modal and select "Inspect".
  • Look for the parent element that has overflow: auto or overflow: scroll in its CSS—this is your scroll container.

Step 2: Scroll the Target Element Directly with JavaScript

Instead of scrolling the main window, target the scrollable container element you found. Here’s how to do it in your code:

Basic Scroll by Pixels

from selenium.webdriver.common.by import By

# Locate the scrollable modal element
scrollable_modal = driver.find_element(By.CLASS_NAME, "_aano")

# Scroll down by 500 pixels within the modal
driver.execute_script("arguments[0].scrollBy(0, 500);", scrollable_modal)

Scroll to the Bottom of the Modal

If you want to scroll all the way to the end (e.g., loading all followers), use this:

driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight;", scrollable_modal)

Step 3: Add Wait to Ensure the Modal Loads

Sometimes the modal might not be fully loaded when you try to interact with it. Use explicit waits to avoid errors:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Wait up to 10 seconds for the scrollable container to appear
scrollable_modal = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.CLASS_NAME, "_aano"))
)

# Now perform the scroll
driver.execute_script("arguments[0].scrollBy(0, 500);", scrollable_modal)

Why Your Original Code Didn’t Work

The window.scrollBy() command only affects the main browser window’s scroll area. Instagram’s modals are nested elements with their own scroll context, so you have to target that specific container instead of the global window.

内容的提问来源于stack exchange,提问作者Khaqan Ahmed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 13:42:38