DEV Community

hub
hub

Posted on

Getting an overview on my Twitter following

`
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))
Enter fullscreen mode Exit fullscreen mode

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.

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs