-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRottenTomatoes.py
33 lines (32 loc) · 1.36 KB
/
RottenTomatoes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from bs4 import BeautifulSoup
import requests
import json, sqlite3
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'}
count = 1
sqliteconnection = sqlite3.connect('db.sqlite3')
cursor = sqliteconnection.cursor()
sql_query = 'SELECT name FROM core_movie;'
cursor.execute(sql_query)
movies = cursor.fetchall()
for movie in movies:
try:
url = 'https://www.rottentomatoes.com/search?search=' + movie[0]
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.content, 'html.parser')
result = soup.find('search-page-media-row')
url = result.find('a')['href']
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
description = soup.find('p', {'data-qa':"movie-info-synopsis"}).text
wtwm = soup.find_all('where-to-watch-meta')
platforms = ''
for _ in wtwm:
platforms += str.title(_['affiliate'].replace('-', ' ').replace('us', '').strip()) + ','
sql_query = f"UPDATE core_movie SET platforms = ?, description = ? WHERE name = ?;"
cursor.execute(sql_query, (platforms, description, movie[0]))
except Exception as e:
print(e)
sqliteconnection.commit()
print(count)
count+=1
sqliteconnection.close()