Created
July 11, 2020 17:50
-
-
Save calvinhp/8362505ec3f72408b96000a66cb5439a to your computer and use it in GitHub Desktop.
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 re | |
from urllib.parse import urlparse | |
import click | |
import requests | |
from bs4 import BeautifulSoup | |
@click.command() | |
@click.argument('url') | |
def grab_twitter_handles(url): | |
res = requests.get(url) | |
soup = BeautifulSoup(res.text, features='html.parser') | |
twit_links = [] | |
for link in soup('a', href=re.compile('twitter.com')): | |
twit_links.append(urlparse(link['href']).path[1:]) | |
print("\n".join(twit_links)) | |
if __name__ == '__main__': | |
grab_twitter_handles() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment