Created
October 13, 2021 19:45
-
-
Save ljmccarthy/f749b683c252fa77061e980ef548c091 to your computer and use it in GitHub Desktop.
Simple script to get all links from a web page
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
#!/usr/bin/env python3 | |
import sys | |
import requests | |
from bs4 import BeautifulSoup | |
def get_links(url): | |
soup = BeautifulSoup(requests.get(url).text, 'html.parser') | |
for a in soup.find_all('a'): | |
href = a.get('href') | |
if href: | |
yield href | |
if __name__ == '__main__': | |
for url in sys.argv[1:]: | |
for link in get_links(url): | |
print(link) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment