Create_FilmDB.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import requests
  2. from bs4 import BeautifulSoup
  3. import sqlite3
  4. from progress.bar import IncrementalBar
  5. from tqdm import tqdm
  6. Database = sqlite3.connect("Film_list.db")
  7. cur = Database.cursor()
  8. cur.execute("""CREATE TABLE IF NOT EXISTS Film_list (
  9. ID INTEGER PRIMARY KEY,
  10. NAME TEXT,
  11. YEAR TEXT,
  12. LINK TEXT)""")
  13. Database.commit()
  14. url = f"https://hd-38.lordfilm-s.me/films/"
  15. r = requests.get(url)
  16. soup = BeautifulSoup(r.text, "lxml")
  17. number_of_films = int(soup.find("div", {"class": "navigation"}).text.split()[-1])
  18. name_year = [""]*24*number_of_films
  19. link = [""]*24*number_of_films
  20. counter = 0
  21. number = 1
  22. bar = IncrementalBar('Download links ', max = number_of_films)
  23. while number <= number_of_films:
  24. r = requests.get(url+f"page/{number}/")
  25. soup = BeautifulSoup(r.text, "lxml")
  26. for i, j, k in zip(soup.find_all("div", class_ = "th-title"),soup.find_all("div", class_ = "th-year"),soup.find_all("div", class_ = "th-item")):
  27. name_year[counter] = i.text + ' ('+ j.text+')'
  28. link[counter] = k.find("a", class_ = "th-in with-mask").get('href')
  29. counter += 1
  30. number += 1
  31. bar.next()
  32. bar.finish()
  33. for i in tqdm(range(24*number_of_films), desc="Upload in Database"):
  34. cur.execute("""INSERT INTO Film_list (NAME, LINK) VALUES(?, ?);""", (name_year[i], link[i]))
  35. Database.commit()