<jupyter_start><jupyter_text>Exercise 2: Collect text content of the book <NAME> available at www.gutenberg.org  Using Requests<jupyter_code>import requests
# Let's read the text version of david copper field available online
r = requests.post('https://www.gutenberg.org/files/766/766-0.txt')
r.status_code
r.text[:1000]
with open ("data_ch4/David_Copperfield.txt", "w", encoding="utf-8") as f:
    f.write(r.text)<jupyter_output><empty_output><jupyter_text>Using Urllib3<jupyter_code>import urllib3
http = urllib3.PoolManager()
rr = http.request('GET', 'https://www.gutenberg.org/files/766/766-0.txt')
rr.status
rr.data[:1000]
open("data_ch4/David_Copperfield_new.txt", 'wb').write(rr.data)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14701803051317613, 'fraction_numerical': 0.04022191400832178, 'mean_word_length': 6.680851063829787, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '109285', 'license': 'MIT', 'n_tokens_mistral': 290, 'n_tokens_neox': 275, 'n_words': 49, 'path': 'Lesson04/Exercise41.ipynb', 'repo_name': 'TrainingByPackt/Natural-Language-Processing-Fundamentals-eLearning', 'size': '732'}