IMDB Top 250 Movies Web Scraping

from urllib.request import urlopen from bs4 import BeautifulSoup import requests import pandas as pd import numpy as np re...


from urllib.request import urlopen
from bs4 import BeautifulSoup
import requests
import pandas as pd
import numpy as np

result=[]
for i in range(1,6):      # Number of pages plus one ,
    url = "https://www.imdb.com/search/title?groups=top_250&my_ratings=exclude&sort=user_rating&page={}".format(i)
    r = requests.get(url)
    soup = BeautifulSoup(r.content)
    c=soup.find_all("div",{"class": "lister-item-content"})
    print(type(c))
    for i in c:
        position = i.find('span',{'class':'lister-item-index unbold text-primary'}).text
        name = i.find('a').text
        year = i.find('span',{'class':'lister-item-year text-muted unbold'}).text
        genre = i.find('span',{'class':'genre'}).text
        rate = i.find('strong').text
        lengthofmovie = i.find('span',{'class':'runtime'}).text
        a_val = i.find_all('a')
        res1 = map(lambda x:x.text,a_val)
        res1 = list(res1)
        director = res1[12]
        stars = ','.join(res1[12:])
        votes = i.find_all('span',{'name':'nv'})
        gross = i.find_all('span',{'name':'nv'})
        #certificate = i.find('span',{'class':'certificate'}).text
        res = [position,name,year,rate,genre,director,stars,votes,gross,lengthofmovie]
        result.append(res)
        

print(res)
print("================================================================================================")
print(result[2])


import csv

with open ('hrmds.csv','r+') as file:
   writer=csv.writer(file)
   writer.writerow(["Rank", "Movie Name", "Release Year", "Rating", "Genre", "Director", "Stars", "Votes", "Gross", "Length of Movie"])
   for i in result:
     writer.writerow(i)

df=pd.read_csv("hrmds.csv",encoding='ISO-8859-1')
df


Above code is written in jupyter notebook so try on jupyter notebook with python version 3. Here first you have to import necessary elements for web scraping. In above scrap beautiful soup is use for web scrap. If the site is complex and want to do automation web scrap then try the selenium.





COMMENTS

Name

Accident Alert,1,AI,2,Array,1,Aurdino,1,C,2,Computer Graphics,9,Data Science,3,Dataset,1,Decoratot,1,Django,1,ESP32,1,Fixed point/iteration method,1,Greater or smaller,1,html,1,Image Processing,1,JAVA,1,Javascript,22,Machine Learning,1,Matlab,3,Numerical Method,13,OOP,1,Other,3,PHP,1,Point operation,1,Python,11,Raspberry pi,1,Recommendation System,1,Regression,1,Reservation System,1,Robotics,1,Simulation,2,sine wave,1,String Handling Function,1,Web scrap,1,Webpage,1,
ltr
item
COMPUTER PROGRAMMING: IMDB Top 250 Movies Web Scraping
IMDB Top 250 Movies Web Scraping
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkQBZk4booYyi5-ycotKT_wUiZ7M9BFVaFQu2FKeAI14oLUZ6I9EHK-9tfMAXotmIJ4xhbXGu4b-d_r5JDHL3mE5VLvGVIGTvEEXRefAgv2JLhLrYedyMeGRa2j86sbTsFl-duZYYlIifE/s640/Screenshot+%2528145%2529.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkQBZk4booYyi5-ycotKT_wUiZ7M9BFVaFQu2FKeAI14oLUZ6I9EHK-9tfMAXotmIJ4xhbXGu4b-d_r5JDHL3mE5VLvGVIGTvEEXRefAgv2JLhLrYedyMeGRa2j86sbTsFl-duZYYlIifE/s72-c/Screenshot+%2528145%2529.png
COMPUTER PROGRAMMING
https://computerprogram4ru.blogspot.com/2018/06/imdb-top-250-movies-web-scraping.html
https://computerprogram4ru.blogspot.com/
https://computerprogram4ru.blogspot.com/
https://computerprogram4ru.blogspot.com/2018/06/imdb-top-250-movies-web-scraping.html
true
8672391763020279633
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy