Created
September 2, 2019 21:06
-
-
Save zedeus/555f9709c1ad744b442bf9a6e9856aaf to your computer and use it in GitHub Desktop.
Fetch Twitter following list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, re, sys | |
url = "https://mobile.twitter.com/{}/following" | |
cursor = "" | |
usernames = [] | |
first = True | |
if len(sys.argv) < 2: | |
print("Usage: python followers.py <username>") | |
quit(1) | |
while True: | |
u = url.format(sys.argv[1]) | |
if not first: | |
u += "?cursor={}".format(cursor) | |
first = False | |
req = requests.get(u) | |
users = re.findall(r"@[^>]+>(.+)</s.+", req.text) | |
usernames.extend(users) | |
c = re.search(r"cursor=([0-9]+)", req.text) | |
if c is not None: | |
cursor = c.groups(0)[0] | |
print(cursor) | |
else: | |
break | |
print(",".join(usernames)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment