Created
December 4, 2019 03:29
-
-
Save calthoff/a9e75f900e4f1f1d4adc6f3ed3da4a8e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 urllib.request | |
| from bs4 import BeautifulSoup | |
| class Scraper: | |
| def __init__(self, site): | |
| self.site = site | |
| def scrape(self): | |
| response = urllib.request.urlopen(self.site) | |
| html = response.read() | |
| sp = BeautifulSoup(html, 'html.parser') | |
| with open("output.txt", "w") as f: | |
| for tag in sp.find_all('a'): | |
| url = tag.get('href') | |
| if url and 'html' in url: | |
| print("\n" + url) | |
| f.write(url + "\n") | |
| Scraper('https://news.google.com/').scrape() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment