I am currently trying to figure out how i could print 1 single story from GoogleNews, now i also have to mention that i am Web Scraping it which makes it even more difficult(i guess). I also tried to google it, but i couldn't really find anything on the internet. So here is my code:
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen
news_url = "https://news.google.com/rss?hl=de&gl=DE&ceid=DE:de"
Client = urlopen(news_url)
xml_page = Client.read()
Client.close()
soup_page = soup(xml_page, "xml")
news_list = soup_page.findAll("item")
for news in news_list:
print(news.title.text)
print(news.link.text)
print(news.pubDate.text)
So when i run this code, it returns a bunch of stories from today, but i only want to print out 1. story. Is there any way to do that?
You can do that using find method as follows:
Or you can use list slicing:
Output: