最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Selenium. Python. Followers list on Instagram's pop-up window doesn't scroll down - Stack Overflow

programmeradmin2浏览0评论

Uses:

python = "^3.12.7"
selenium = "^4.30.0"

Initialize variable "driver":

from time import sleep
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdrivermon.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdrivermon.action_chains import ActionChains
from selenium.webdrivermon.by import By


driver = webdriver.Chrome()
driver.get('/')
sleep(3)

#   *   *   *
#   Sign in code here
#   *   *   *

#  chose user account for example:
driver.get('/')
sleep(3)

driver.find_element(By.PARTIAL_LINK_TEXT, 'followers').click()
print('4')

#  set followers pop-up list to new variable (i checked four XPATH based on the page code source, see img below):
pop_up_window = driver.find_element(By.XPATH, "//div[@role='dialog']")
#  and
#  pop_up_window = driver.find_element(By.XPATH, '/html/body/div[4]/div[2]/div/div/div[1]/div/div[2]/div/div/div/div/div[2]/div/div/div[3]')
#  and
#  pop_up_window = driver.find_element(By.XPATH, '/html/body/div[4]/div[2]/div/div/div[1]/div/div[2]/div/div/div/div/div[2]/div/div/div[3]/div[1]')
#  and
#  pop_up_window = driver.find_element(By.XPATH, '/html/body/div[4]/div[2]/div/div/div[1]/div/div[2]/div/div/div/div/div[2]/div/div/div[3]/div[1]/div')

then i uses few difference variants for try to scroll down:

1st. - uses ActionChains from selenium.webdrivermon.action_chains:

num_chains = 10
for _ in range(num_chains):
    print('=========== Chains Start =================')
    ActionChains(driver).send_keys(Keys.END).perform()

2nd. - uses javascript:

v2.1

while True:
    driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", pop_up_window)
    sleep(2)

v2.2

while True:
    driver.execute_script('arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;', pop_up_window)
    sleep(2)

v2.3

num_chains = 10
followers_step = 10
for _ in range(num_chains):
   driver.execute_script("arguments[0].scrollTop = arguments[1]", pop_up_window, followers_step)
   followers_step += followers_step
   sleep(3)

finally i get followers pop-up window by which i should make scroll down but the slider for scrolling to the right doesn't appear and the user-list does not scroll, on the output i always get the same result that was immediately opening at followers pop-up list (noticed that when the scrolling process starts - the closing button is highlighted always):

and I always get the same result without scrolling:

p.s.: answers: this and this - already discussed at stackoverflow did not help

发布评论

评论列表(0)

  1. 暂无评论