Example 1:

import requests
from bs4 import BeautifulSoup

def saveFile( filename, content ):
   with open(filename, "w") as w:
        w.write(content+"\n")

if __name__ == "__main__":
   # Load the content of the website
     url = "https://news.google.com/gn/news/?hl=en"
     page = requests.get(url)
     print( page.content ) # Will print the content of the webpage

     # Run our page through BeautifulSoup and prettify it
     soup = BeautifulSoup( page.content, "html.parser" )
     pretty = soup.prettify()
     saveFile( "output.txt", pretty )

     # Let's get the news headlines
     print( "Page title: "+soup.title.string )

     for headline in soup.find_all("a", role="heading", limit=20):
        print( headline.string ) # the text content inside the tag
            print( headline.get("href") ) # get content of the href attribute

Example 2

import requests
from bs4 import BeautifulSoup

def saveFile( filename, content ):
   with open(filename, "w") as w:
        w.write(content+"\n")

if __name__ == "__main__":
   # Load the content of the website
     url = "https://news.google.com/gn/news/?hl=en"
     page = requests.get(url)
     print( page.content ) # Will print the content of the webpage

     # Run our page through BeautifulSoup and prettify it
     soup = BeautifulSoup( page.content, "html.parser" )
     pretty = soup.prettify()
     saveFile( "output.txt", pretty )

     # Let's get the news headlines
     print( "Page title: "+soup.title.string )

     for headline in soup.find_all("a"):
        if headline.parent.parent.get("class") is not None:
               if "doctype-article" in headline.parent.parent.get("class"):
                        print( headline.string ) # the text content inside the tag
                        print( headline.get("href") ) # get content of the href attribute

A couple of other things: