Skip to content

Instantly share code, notes, and snippets.

@BensonMuriithi
Created August 7, 2016 07:46
Show Gist options
  • Save BensonMuriithi/b22d1556b4295211c831e94798440990 to your computer and use it in GitHub Desktop.
Save BensonMuriithi/b22d1556b4295211c831e94798440990 to your computer and use it in GitHub Desktop.
My solution for 'Decode A Web Page' exercise on practicepython.org ->http://www.practicepython.org/exercise/2014/06/06/17-decode-a-web-page.html
"""Get all <article> tags on New York Times homepage"""
import requests
from bs4 import BeautifulSoup
def get_articles(address):
page = requests.get(address)
soup = BeautifulSoup(page.text, "html.parser")
return list(soup.find_all("article"))
if __name__ == "__main__":
print get_articles("http://www.nytimes.com/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment