问题描述
我正在使用 selenium 并尝试在 instagram 上的弹出 div 内滚动.
I am using selenium and trying to scroll inside the popup div on instagram.
我进入了一个类似https://www.instagram.com/kimkardashian/的页面',点击关注者,然后我无法让关注者列表向下滚动.
I get to a page like 'https://www.instagram.com/kimkardashian/', click followers, and then I can't get the followers list to scroll down.
我尝试使用悬停、click_and_hold 和其他一些技巧来选择 div,但都没有奏效.
I tried using hover, click_and_hold, and a few other tricks to select the div but none of them worked.
选择此选项的最佳方法是什么?
What would the best way be to get this selected?
这是我目前尝试过的:
driver.find_elements_by_xpath("//*[contains(text(), 'followers')]")[0].click()
element_to_hover_over = driver.find_elements_by_xpath("//*[contains(text(), 'Follow')]")[12]
hover = ActionChains(webdriver).move_to_element(element_to_hover_over)
hover.click_and_hold()
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
推荐答案
具体代码如下.您首先必须找到包含关注者名称的新 iframe:
The exact code is as follow. You first have to find the new iframe which contains the name of followers:
scr1 = driver.find_element_by_xpath('/html/body/div[2]/div/div[2]/div/div[2]')
driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", scr1)
这将自动向下滚动页面,但您已经为它创建了一个 for 循环,直到它到达页面的末尾.您可以在此处查看我的 Instagram 爬虫.
This will automatically scroll down the page but you have make a for loop for it until it reaches to the end of page. You can see my Instagram crawler here.
这篇关于弹出div里面的硒滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!