使用 Selenium 从 Twitter 抓取关注者

Scraping followers from Twitter using Selenium

我是 Python 的新手,一直在尝试编写一个可以从 Twitter 抓取数据的应用程序。我尝试在堆栈和互联网上搜索所有类似的可能解决方案,但失败了。

我想抓取所有这些用户名: See here

这是我的代码:

driver.get("https://twitter.com/twitterusername/followers")
sleep(10)

usernames = driver.find_elements_by_class_name("css-901oao.css-16my406.r-poiln3.rbcqeeo.r-qvutc0")
for username in usernames:
    print(username.get_attribute("href"))

我得到的结果:

None
None
None
None
None
None
None

...

感谢您的帮助。

所以,使用 BeautifulSoup 是关闭 table。 我们只能使用 selenium 来处理这个问题。

for a in driver.find_elements_by_xpath('//div[@aria-label="Timeline: Followers"]//a[@role="link"]'):
    url = a.get_property('href')
    if 'search' in url:
        return 
    print(url.replace("https://twitter.com/", "@")