#!/usr/bin/env python3

import urllib.request
import urllib.error

def count_words_file(url):
    try:
        file_response = urllib.request.urlopen(url)
    except urllib.error.URLError as error:
        print('Wyjątek:', error)
        print('Przyczyna:', error.reason)
    else:
        content = file_response.read(3000000)
        return len(content.split())

#print(count_words_file('https://www.gutenberg.org/cache/epub/2000/pg2000.txt'))
print(count_words_file('https://helion.pl'))
print(count_words_file('https://nie-istnieje.txt'))