-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtwitter.py
More file actions
51 lines (41 loc) · 1.42 KB
/
Copy pathtwitter.py
File metadata and controls
51 lines (41 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import bs4
import requests
import operator
from halo import Halo
user_id = input("Enter the username of the Twitter profile:\n")
user_link = "https://twitter.com/" + user_id
spinner = Halo(text="Scraping info...", spinner="dots")
spinner.start()
res = requests.get(user_link)
soup = bs4.BeautifulSoup(res.text, "lxml")
name = soup.select(".ProfileHeaderCard-nameLink.u-textInheritColor.js-nav")
try:
count = []
for item in soup.findAll("span", {"class": "ProfileNav-value"}):
count.append(item.get("data-count"))
except IndexError:
print("Error: missing or broken info!")
try:
join = soup.select(".ProfileHeaderCard-joinDateText.js-tooltip.u-dir")
joined = join[0].get("title")
except IndexError:
print("Error: missing or broken info!")
spinner.stop()
try:
print("\nSummary for Twitter user @{} (aka {}):".format(
user_id, name[0].text))
except IndexError:
print("Error: missing or broken info!")
try:
print("\nNumber of Tweets: {}".format(count[0]))
print("Number of following: {}".format(count[1]))
print("Number of followers: {}".format(count[2]))
print("Number of likes: {}".format(count[3]))
print("Number of lists: {}".format(count[4]))
print("Number of moments: {}".format(count[5]))
except IndexError:
print("Error: missing or broken info!")
try:
print("\nJoined Twitter at: {}".format(joined))
except IndexError:
print("Error: missing or broken info!")