Created
April 13, 2018 18:09
-
-
Save bourke/765a9cc08596a5666184be8f7d8eea1e to your computer and use it in GitHub Desktop.
Plums for @ftrain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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