forked from SBDeveloper10/movies-downloader-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
movies_scraper.py
41 lines (34 loc) · 1.54 KB
/
movies_scraper.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
34
35
36
37
38
39
40
41
import requests
from bs4 import BeautifulSoup
url_list = {}
api_key = "998eb1cb629e1193c1355f6b5168e2b4ffc282bc"
def search_movies(query):
movies_list = []
movies_details = {}
website = BeautifulSoup(requests.get(f"https://mkvcinemas.skin/?s={query.replace(' ', '+')}").text, "html.parser")
movies = website.find_all("a", {'class': 'ml-mask jt'})
for movie in movies:
if movie:
movies_details["id"] = f"link{movies.index(movie)}"
movies_details["title"] = movie.find("span", {'class': 'mli-info'}).text
url_list[movies_details["id"]] = movie['href']
movies_list.append(movies_details)
movies_details = {}
return movies_list
def get_movie(query):
movie_details = {}
movie_page_link = BeautifulSoup(requests.get(f"{url_list[query]}").text, "html.parser")
if movie_page_link:
title = movie_page_link.find("div", {'class': 'mvic-desc'}).h3.text
movie_details["title"] = title
img = movie_page_link.find("div", {'class': 'mvic-thumb'})['data-bg']
movie_details["img"] = img
links = movie_page_link.find_all("a", {'rel': 'noopener', 'data-wpel-link': 'internal'})
final_links = {}
for i in links:
url = f"https://urlshortx.com/api?api={api_key}&url={i['href']}"
response = requests.get(url)
link = response.json()
final_links[f"{i.text}"] = link['shortenedUrl']
movie_details["links"] = final_links
return movie_details