Python Web Scraping: Get the number of following on a Twitter account
Python Web Scraping: Exercise-17 with Solution
Write a Python program to get the number of "following" on a Twitter account.
Sample Solution:
Python Code:
from bs4 import BeautifulSoup
import requests
handle = input('Input your account name on Twitter: ')
temp = requests.get('https://twitter.com/'+handle)
bs = BeautifulSoup(temp.text,'lxml')
try:
following_box = bs.find('li',{'class':'ProfileNav-item ProfileNav-item--following'})
following = following_box.find('a').find('span',{'class':'ProfileNav-value'})
print("{} is following {} people.".format(handle,following.get('data-count')))
except:
print('Account name not found...')
Sample Output:
Input your account name on Twitter: @prasanta @prasanta is following 110 people.
Flowchart:

Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to get the number of followers of a given twitter account.
Next: Write a Python program to get the number of post on Twitter liked by a given account.
What is the difficulty level of this exercise?
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join