Skip to content

Instantly share code, notes, and snippets.

@bourke
Created April 13, 2018 18:09
Show Gist options
  • Save bourke/765a9cc08596a5666184be8f7d8eea1e to your computer and use it in GitHub Desktop.
Save bourke/765a9cc08596a5666184be8f7d8eea1e to your computer and use it in GitHub Desktop.
Plums for @ftrain
from bs4 import BeautifulSoup
import requests
def fetch_html():
res = requests.get('https://www.poets.org/poetsorg/poem/just-say')
return res.content
def parse_content(html):
soup = BeautifulSoup(html)
containers = soup.find(id="poem-content").find_all('pre')
if containers:
container = containers[0]
words = container.text.split()
return words
def write_content(content):
for i, word in enumerate(w.lower() for w in content):
print(f"{i + 21}. {word}")
def main():
html = fetch_html()
parsed = parse_content(html)
if parsed:
write_content(parsed)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment