`
Well I think it's possible to extend the following script to get the following people of my Twitter account too
`
from bs4 import BeautifulSoup
import requests
handle = input('Input the Twitter account name: ')
url = 'https://twitter.com/' + handle
temp = requests.get(url)
bs = BeautifulSoup(temp.text, 'html.parser')
try:
# Extracting account name
account_name = bs.find('a', {'class': 'ProfileHeaderCard-nameLink u-textInheritColor js-nav'}).text.strip()
# Extracting followers count
follow_box = bs.find('li', {'class': 'ProfileNav-item ProfileNav-item--followers'})
followers = follow_box.find('a').find('span', {'class': 'ProfileNav-value'})
followers_count = followers.get('data-count')
print("Account Name: {}".format(account_name))
print("Number of Followers: {}".format(followers_count))
except AttributeError:
print('Account name not found or private account.')
`
This above script will be able to display both the account name and the number of followers. But wait I want to get the following people of my Twitter account too.
Top comments (0)