nacbotics avatar

google news via python

nacbotics

Published: 09 Oct 2019 › Updated: 09 Oct 2019

google news via python

hello steemians i will be showing you guys how to access google news in python

first off let's import the neccessary modules

import requests
from bs4 import BeautifulSoup as soup

secondly we create a function for accessing the news via google

def feeds(self):
db = [] #this is a list that holds all the news gathered
news_url = "https://news.google.com/news/rss" #google news web directory
Client=requests.get(news_url) #here we make a call to access the contents of the url
xml_page=Client.content #basically returns the contents of the url
soup_page=soup(xml_page,"xml") #for processing webpages in python
news_list=soup_page.findAll("item") #returns all tags "item" in the web page
for news in news_list[:15]:#returns the top 10 news
db.append(news.title.text.encode('utf-8'))
return("here is the top 10 trending news. \n\n%s"%".\n".join(db)) #a return call

Leave google news via python to:

Written by

Read more #diy posts


Best Posts From nacbotics

We have not curated any of nacbotics's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From nacbotics