Python 抓取Instagram追随者的帐户

Python 抓取Instagram追随者的帐户,python,selenium,web-scraping,instagram,Python,Selenium,Web Scraping,Instagram,我试图通过使用Selenium从Instagram帐户中抓取追随者。() 我需要向下滚动一个弹出页面,但我唯一能向下滚动的是后面的页面 这是我的密码 scr1 = driver.find_element_by_xpath('/html/body/div[4]/div/div') driver.execute_script("window.scrollTo(0, document.body.scrollHeight);",scr1) ## Scroll to bottom o

我试图通过使用Selenium从Instagram帐户中抓取追随者。()

我需要向下滚动一个弹出页面,但我唯一能向下滚动的是后面的页面

这是我的密码

scr1 = driver.find_element_by_xpath('/html/body/div[4]/div/div')
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);",scr1)  ## Scroll to bottom of page with using driver
我还尝试在我的JS浏览器控制台中使用对话框模式的JSPath:

window.scrollTo(0, document.querySelector("body > div.RnEpo.Yx5HN > div"));

(已经看到了与堆栈相关的帖子,但答案似乎在2020年10月被弃用了)

我对您尝试做的事情也有类似的问题。目前,我在脚本中实现的方法使用Selenium的
ActionChains
类,我发现它比所有Javascript(
execute\u script
)答案都有用得多

基本上,我使用
ActionChains
按下“向下”箭头键,然后对其进行操作。我将在下面列出基本语法:

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(browser)
actions.send_keys(Keys.DOWN).perform() #sends a general down arrow key to the page 
现在我将
ActionChains
集中在一个特定的元素上,在本例中是弹出窗口。有很多方法可以关注元素,但我发现最简单的解决方法是在使用
ActionChains

像这样:

popup = driver.find_element_by_class_name('popupClass') #you don't have to use class_name
for i in range(500): #500 is amount of scrolls
    popup.click() #focus the down key on the popup
    actions.send_keys(Keys.DOWN).perform() # press the down key

上述方法将单击弹出窗口,然后按下向下键一次,基本上向弹出窗口发送500个“滚动”,而不是整个页面。完成后,您需要获取负责弹出窗口的元素上的
.text
属性(至少我在脚本中就是这么做的)。

Hello@ohan shah-ty,请回答。您的代码中的“浏览器”是什么?这一行给了我一个错误,我无法判断我的变量“browser”和你的变量“driver”是一样的。如果复制我的代码,只需将单词
browser
替换为
driver
。另外,确保用实际的类名填写
弹出窗口
类名