Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to Profile a Python Program - Block 2
import requests
from bs4 import BeautifulSoup
def get_word_count_of(url: str) -> int:
res = requests.get(url)
if res.status_code == 200:
_data = res.text
return count_words(_data)
return 0
def count_words(data: str) -> int:
_parsed_html = BeautifulSoup(data)
_paragraphs = [p.text for p in _parsed_html.body.find_all('p')]
return sum([p.count(' ') for p in _paragraphs])
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment