-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
32 lines (27 loc) · 1007 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import requests
import webbrowser
from bs4 import BeautifulSoup
class Scraper:
def __init__(self, keywords):
self.markup = requests.get('https://news.ycombinator.com/').text
self.keywords = keywords
self.parse()
self.outputHTML()
def parse(self):
soup = BeautifulSoup(self.markup, 'html.parser')
links = soup.find_all('a',{'class': 'storylink'})
self.savedlinks = []
for link in links:
for keyword in self.keywords:
if keyword in link.text:
self.savedlinks.append(link)
def outputHTML(self):
f = open('TodaysNews.html', 'w')
body = " "
for link in self.savedlinks:
body += str(link)+ "<br><br>"
f.write("<header><title>News of the Day</title><link rel="'stylesheet'" href="'style.css'"></header><body>")
f.write(body)
f.write("</body>")
f.close()
webbrowser.open_new_tab('TodaysNews.html')