Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a feature for News Headlines #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions News Headlines/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# News Headlines


## Packages Used

### bs4
`bs4` (Beautiful Soup) uses a pluggable XML or HTML parser to parse a (possibly invalid) document into a tree representation. `bs4` (Beautiful Soup) provides methods and Pythonic idioms that make it easy to navigate, search, and modify the parse tree.
`bs4` (Beautiful Soup) works with Python 2.7 and up. It works better if lxml and/or html5lib is installed.

### urllib
`urllib` is a package that collects several modules for working with URLs:

+ `urllib.request` for opening and reading URLs

+ `urllib.error` containing the exceptions raised by urllib.request

+ `urllib.parse` for parsing URLs

+ `urllib.robotparser` for parsing `robots.txt` files


## Source
![ss2](https://user-images.githubusercontent.com/83420185/118469931-d332eb00-b723-11eb-9482-284f8e1cce73.png)


## Console
![ss1](https://user-images.githubusercontent.com/83420185/118470093-fd84a880-b723-11eb-85ae-53b52bb01591.png)
20 changes: 20 additions & 0 deletions News Headlines/news.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Fetching news headlines from google news

import bs4
from urllib.request import urlopen

url = "https://news.google.com/news/rss"
client = urlopen(url)
xml_page = client.read()
client.close()
page = bs4.BeautifulSoup(xml_page, 'xml')
news_list = page.findAll("item")
print("Today's top headlines are--")
try:
for news in news_list:
print(news.title.text)
# print(news.pubDate.text)
print()

except Exception as e:
pass