Python 在Instagram框中向下滚动关注者/以下列表
您好:)我正在寻找一种解决方案,以便在Instagram框中向下滚动以下/关注者列表。 我执行的步骤如下:Python 在Instagram框中向下滚动关注者/以下列表,python,selenium,instagram,Python,Selenium,Instagram,您好:)我正在寻找一种解决方案,以便在Instagram框中向下滚动以下/关注者列表。 我执行的步骤如下: 打开用户A的IG配置文件 点击“追随者”按钮 IG框中会出现一个包含12个跟随者列表的框 显示追随者列表后,当我使用以下行向下滚动时: driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") 我发现框下方的页面向下滚动:( 如何在followers框中向下滚动列表 提前感谢:) Maria。您可
- 打开用户A的IG配置文件李>
- 点击“追随者”按钮李>
- IG框中会出现一个包含12个跟随者列表的框
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
我发现框下方的页面向下滚动:(
如何在followers框中向下滚动列表
提前感谢:)
Maria。您可以尝试执行
脚本()
并更改.isgrP
,如果不同的类
...
from selenium.webdriver.support.ui import WebDriverWait
.....
# after click follower link, wait until dialog appear
WebDriverWait(driver, 10).until(lambda d: d.find_element_by_css_selector('div[role="dialog"]'))
# now scroll
driver.execute_script('''
var fDialog = document.querySelector('div[role="dialog"] .isgrP');
fDialog.scrollTop = fDialog.scrollHeight
''')
这种方法非常适合我的情况。请不要改变循环中的睡眠时间。它们允许在对话框中重新加载追随者/追随者,而无需向上滚动
FList = driver.find_element_by_css_selector('div[role=\'dialog\'] ul')
numberOfFollowersInList = len(FList.find_elements_by_css_selector('li'))
FList.click()
actionChain = webdriver.ActionChains(driver)
time.sleep(random.randint(2,4))
while (numberOfFollowersInList < max):
actionChain.key_down(Keys.SPACE).key_up(Keys.SPACE).perform()
numberOfFollowersInList = len(FList.find_elements_by_css_selector('li'))
time.sleep(0.4)
print(numberOfFollowersInList)
actionChain.key_down(Keys.SPACE).key_up(Keys.SPACE).perform()
time.sleep(1)
FList=driver。通过css\u选择器('div[role=\'dialog\']ul'查找\u元素\u)
numberOfFollowersInList=len(FList.find_元素由_css_选择器('li'))
FList.click()
actionChain=webdriver.ActionChains(驱动程序)
时间.睡眠(随机.随机数(2,4))
while(numberOfFollowersInList
您可以测试以下方法。我测试过了,它能工作
"""Scroll a specific element one or more times with small delay between
them."""
while times > 0:
self.driver.execute_script(
'arguments[0].scrollTop = arguments[0].scrollHeight',
element
)
time.sleep(.2)
times -= 1
太好了:)谢谢。。。它有效:)只有一个澄清。我使用time.sleep(3)等待,因为使用您的代码会返回:WebDriverWait未定义。。。即使我导入:从selenium从selenium.webdriver.common.keys导入keys导入webdriver也不客气。已编辑答案,添加所需导入,如果已解决,请将答案标记为正确。感谢您的解决方法。我已经试着解决这个问题5个小时了。@ewlink