<jupyter_start><jupyter_text>Python Web Scraping using BeautifulSoup In this example, we will be getting yearly U.S. unemployment rates from the Bureau of Labor Statisticis web site<jupyter_code>from bs4 import BeautifulSoup
from urllib import request
import numpy as np

monthly_unemployment_data = request.urlopen('http://www.bls.gov/web/empsit/cpseea03.htm')
lines_list = monthly_unemployment_data.readlines()

index = 0
for line in lines_list:
    index = index + 1
    if "cps_eande_m03.r.2 cps_eande_m03.r.2.1 cps_eande_m03.r.2.1.3" in line.decode("utf-8"):
        break

start_index = index
print("start index:", start_index)
        
for line in lines_list[index:]:
    index = index + 1
    if "</tr>" in line.decode("utf-8"):
        break

end_index = index
print("End index:", end_index)

data_string = ""
for data in lines_list[start_index:end_index-1]:
    data_string = data_string + data.decode("utf-8")

print("data string:")    
print(data_string)
soup = BeautifulSoup(data_string)
data = soup.find_all(class_="datavalue")

unemploy_rate = [float(rate.text) for rate in data]
print(unemploy_rate)

bar(np.arange(len(unemploy_rate)),unemploy_rate)
show()<jupyter_output>[6.7, 6.6, 6.2, 6.3, 6.1, 6.2, 6.1, 5.9, 5.7, 5.8, 5.6, 5.7, 5.5]
{'fraction_non_alphanumeric': 0.12928970470869913, 'fraction_numerical': 0.03830806065442937, 'mean_word_length': 4.428571428571429, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '263505', 'license': 'MIT', 'n_tokens_mistral': 508, 'n_tokens_neox': 478, 'n_words': 113, 'path': 'web_scraping/Monthly_Unemployment_Rate.ipynb', 'repo_name': 'manual123/Nacho-Jupyter-Notebooks', 'size': '1253'}