Created
July 19, 2017 14:48
-
-
Save aaronsaderholm/1e67b6f135d486bf144a028790d2d1ae to your computer and use it in GitHub Desktop.
Pull Links from HTML using Python/BS4
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 python | |
from bs4 import BeautifulSoup | |
import sys | |
input_file = sys.argv[1] | |
output_file = sys.argv[2] | |
ifile = open(input_file, "r") | |
html = ifile.read() | |
ifile.close() | |
links = [] | |
soup = BeautifulSoup(html) | |
for link in soup.findAll('a'): | |
url = link.get('href') | |
print(url) | |
links.append(link.get('href')) | |
ofile = open(output_file, "w") | |
for link in links: | |
ofile.write(link + "\n") | |
ofile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment