<jupyter_start><jupyter_text>Web Scraping:1. Import the libraries and classes:    - urllib request.    - BeautifulSoup.2. Steps:    a. html upload.    b. html parser.    c. Extraction of data from web page.    d. Transformation into required file: csv.<jupyter_code># Import useful libraries and classes.
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
#html upload
my_url=  "http://www.imdb.com/search/title?sort=num_votes,desc&start=1&title_type=feature&year=1950,2012"
uClient= uReq(my_url)
page_html= uClient.read()
uClient.close()
page_html
#html parser
page_soup= soup(page_html)
page_soup
#read class from web page.
containers= page_soup.findAll("div", {"class": "lister-item mode-advanced"})
print(len(containers))
votes= containers[9].findAll("span", {"name": "nv"})

print(votes[0].text)
filename= "imdb_m.csv"
f= open(filename, "w")

headers= "Name, Year, Runtime \n"
f.write(headers)

for container in containers:
    name= container.img["alt"]
    year_mov= container.findAll("span", {"class": "lister-item-year"})
    year=year_mov[0].text
    runtime_mov= container.findAll("span", {"class": "runtime"})
    runtime=runtime_mov[0].text
    
    print(name + "," + year + "," + runtime +  "\n")
    f.write(name + "," + year + "," + runtime  + "\n")
    
f.close()
import pandas as pd
imdb = pd.read_csv('imdb_m.csv', encoding='latin1')
imdb.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15649122807017543, 'fraction_numerical': 0.011929824561403509, 'mean_word_length': 4.75, 'pattern_counts': {'":': 4, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '142829', 'license': 'MIT', 'n_tokens_mistral': 522, 'n_tokens_neox': 505, 'n_words': 122, 'path': 'Web+Scraping_imdb.ipynb', 'repo_name': 'nirbaaytandon/Data-Science', 'size': '1425'}