Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bilalozdemir/a95a4779c36e76d5c4d0ce1443291e63 to your computer and use it in GitHub Desktop.
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__':
get_word_count_of('https://example.org/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment