Facebook
From Cute Hamerkop, 4 Months ago, written in Python.
Embed
Download Paste or View Raw
Hits: 50
  1. import sqlite3
  2. import requests
  3. from bs4 import BeautifulSoup
  4.  
  5.  
  6. def create_chart():
  7.     cursor.execute("CREATE TABLE IF NOT EXISTS IMDbTop250 (MovieName TEXT,MovieDate TEXT,MoviePoint TEXT)")
  8. def add_data(conn,MovieName,MovieDate,MoviePoint):
  9.     cursor.execute("INSERT INTO IMDbTop250 (MovieName,MovieDate,MoviePoint) VALUES (?,?,?)",(MovieName,MovieDate,MoviePoint))
  10.     con.commit()
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. if __name__ == "__main__":
  18.     con=sqlite3.connect("DBLectures.db")
  19.     cursor=con.cursor()
  20.     create_chart()
  21.     imdb="https://www.imdb.com/chart/top/"
  22.     r=requests.get(imdb)
  23.     soup=BeautifulSoup(r.content,"html.parser")
  24.     data=soup.find_all("table",{"class":"chart full-width"})
  25.     movietable=(data[0].contents)[len(data[0].contents)-2]
  26.     movietable= movietable.find_all("tr")
  27.  
  28.     for movie in movietable:
  29.         movietitle=movie.find_all("a")
  30.         moviename=movietitle[1].text
  31.         movietitle=movie.find_all("span",{"class":"secondaryInfo"})
  32.         moviedate=movietitle[0].text
  33.         moviedate=moviedate.replace("(","")
  34.         moviedate=moviedate.replace(")","")
  35.         movietitle=movie.find_all("td",{"class":"ratingColumn imdbRating"})
  36.         moviepoint=movietitle[0].text
  37.         moviepoint=moviepoint.replace("\n"," ")
  38.         add_data(con,moviename,moviedate,moviepoint)
  39.  
  40.  
  41.     con.close()