我正在尝试获取给定Twitter帐户的关注者列表。为此,我设法使用Selenium和PhantomJS(v2.1.1)连接到我的帐户。 然后,由于Twitter使用无限滚动,我想实现以下算法:
1/ Count the number of html elements with class attribute equals ProfileCard-screennameLink
2/ Repeat:
-Scroll down
-Count the number of html elements with class attribute equals ProfileCard-screennameLink
Until the number of elements does not change
我的问题是滚动功能不起作用。的确,当我跑步时
elemsCount = browser.execute_script("return document.querySelectorAll('.ProfileCard-screennameLink').length")
print("c", elemsCount)
browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(10)
elemsCount = browser.execute_script("return document.querySelectorAll('.ProfileCard-screennameLink').length")
print("c (new)", elemsCount)
检索到的HTML元素数量没有变化(在页面高度上也没有)。看起来scrollTo
函数没有影响。
您有任何解释或解决方法可以解决我的问题吗?