import sqlite3
import requests
from bs4 import BeautifulSoup
def create_chart():
cursor.execute("CREATE TABLE IF NOT EXISTS IMDbTop250 (MovieName TEXT,MovieDate TEXT,MoviePoint TEXT)")
def add_data(conn,MovieName,MovieDate,MoviePoint):
cursor.execute("INSERT INTO IMDbTop250 (MovieName,MovieDate,MoviePoint) VALUES (?,?,?)",(MovieName,MovieDate,MoviePoint))
con.commit()
if __name__ == "__main__":
con=sqlite3.connect("DBLectures.db")
cursor=con.cursor()
create_chart()
imdb="https://www.imdb.com/chart/top/"
r=requests.get(imdb)
soup=BeautifulSoup(r.content,"html.parser")
data=soup.find_all("table",{"class":"chart full-width"})
movietable=(data[0].contents)[len(data[0].contents)-2]
movietable= movietable.find_all("tr")
for movie in movietable:
movietitle=movie.find_all("a")
moviename=movietitle[1].text
movietitle=movie.find_all("span",{"class":"secondaryInfo"})
moviedate=movietitle[0].text
moviedate=moviedate.replace("(","")
moviedate=moviedate.replace(")","")
movietitle=movie.find_all("td",{"class":"ratingColumn imdbRating"})
moviepoint=movietitle[0].text
moviepoint=moviepoint.replace("\n"," ")
add_data(con,moviename,moviedate,moviepoint)
con.close()
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}