├── __pycache__ └── scraper.cpython-310.pyc ├── main.py └── scraper.py /__pycache__/scraper.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenferhatAymen/flask-api-movies-scraper/HEAD/__pycache__/scraper.cpython-310.pyc -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, jsonify, request 2 | from scraper import * 3 | from flask_restful import Api, Resource 4 | 5 | app = Flask(__name__) 6 | api = Api(app) 7 | 8 | 9 | class MovieSearch(Resource): 10 | def get(self, movieName): 11 | a = searchShow(movieName) 12 | return jsonify({"data": a}) 13 | 14 | 15 | class ShowLinks(Resource): 16 | def get(self): 17 | movieLink = request.headers.get("link") 18 | 19 | a = getWatchLinks(movieLink) 20 | return jsonify({"data": a}) 21 | 22 | 23 | api.add_resource(MovieSearch, "/moviesearch/") 24 | api.add_resource(ShowLinks, "/showlinks") 25 | 26 | if __name__ == "__main__": 27 | app.run(debug=True) 28 | -------------------------------------------------------------------------------- /scraper.py: -------------------------------------------------------------------------------- 1 | # importing necessary libraries 2 | import requests 3 | from lxml import html 4 | 5 | baseUrl = "https://weciimaa.online/" 6 | 7 | 8 | def setQueue(text): 9 | return text.replace(" ", "+") 10 | 11 | 12 | def searchShow(searchQueue): 13 | searchQueue = setQueue(searchQueue) 14 | page = requests.get( 15 | "https://weciimaa.online/search/{}/#webpage".format(searchQueue) 16 | ) 17 | tree = html.fromstring(page.text) 18 | showLinks = tree.xpath('//div[@class="Thumb--GridItem"]/a/@href') 19 | showNames = tree.xpath('//div[@class="Thumb--GridItem"]/a/@title') 20 | 21 | return showNames, showLinks 22 | 23 | 24 | def getWatchLinks(showLink): 25 | page = requests.get(showLink) 26 | tree = html.fromstring(page.text) 27 | watchLinks = tree.xpath('//ul[@class="WatchServersList"]/ul/li/btn/@data-url') 28 | serverNames = tree.xpath('//ul[@class="WatchServersList"]/ul/li/btn/strong/text()') 29 | 30 | return watchLinks, serverNames 31 | 32 | 33 | # print( 34 | # getWatchLinks( 35 | # "https://weciimaa.online/watch/%d9%85%d8%b4%d8%a7%d9%87%d8%af%d8%a9-%d9%81%d9%8a%d9%84%d9%85-avengers-endgame-2019-%d9%85%d8%aa%d8%b1%d8%ac%d9%85/" 36 | # ) 37 | # ) 38 | --------------------------------------------------------------------------------