Skip to content

Instantly share code, notes, and snippets.

@calvinhp
Created July 11, 2020 17:50
Show Gist options
  • Save calvinhp/8362505ec3f72408b96000a66cb5439a to your computer and use it in GitHub Desktop.
Save calvinhp/8362505ec3f72408b96000a66cb5439a to your computer and use it in GitHub Desktop.
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