Python 使用selenium和phantomjs抓取Twitter关注者页面
我正在尝试获取给定Twitter帐户的关注者列表。为此,我使用Selenium和PhantomJS(v2.1.1)连接到我的帐户。 然后,由于Twitter使用无限滚动,我想实现以下算法:Python 使用selenium和phantomjs抓取Twitter关注者页面,python,selenium,twitter,phantomjs,Python,Selenium,Twitter,Phantomjs,我正在尝试获取给定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 ele
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
功能没有影响。
你有什么解释或解决方法来解决我的问题吗?为什么你不使用Python的众多twitter模块中的任何一个,例如?我项目的一部分是使用Tweepy(获取当前趋势),但关键是由于API速率限制,而且我想收集大量帐户的追随者,在这种情况下,使用Tweepy与我无关。如果twitter会通过他们的API对你进行评级限制,你可以打赌他们也不会希望你从他们的网站获取那么多数据。谢谢你的评论,但这不是重点。当使用Safari作为Selenium的web驱动程序时,我确实成功了。我的问题是在使用PhantomJS而不是Safari时(我确实需要使用PhantomJS,因为我计划在其上运行代码的服务器尚未安装server X)。我面临着同样的问题,您是否找到了@YoannPitarch的解决方案?