Untitled
unknown
typescript
2 years ago
1.2 kB
4
Indexable
import axios from "axios"; import cheerio from "cheerio"; import {Source} from "./types"; const sourceScraper = async (url: string) => { const {data} = await axios.get(url); const $ = cheerio.load(data); const sources = $(".keremiya_part a") .map((i, el) => { return {url: $(el).attr("href") as string, text: $(el).text()}; }) .toArray(); return { current: { url: url, text: $(".keremiya_part > span").text(), }, alternatives: sources, }; }; const videoScraper = async (source: Source) => { const {data} = await axios.get(source.url); const $ = cheerio.load(data); const video = $("iframe").attr("src"); if (!video) throw new Error("Video not found"); if (video.startsWith("https") || video.startsWith("http")) return video; const videoUrl = "https:" + video; return videoUrl; }; const main = async () => { const sources = await sourceScraper( "https://www.fullhdizle.me/panama-film-izle/" ); const alternatives = sources.alternatives.map(async (source: Source) => { return {url: await videoScraper(source), text: source.text}; }); console.log(await Promise.all(alternatives)); }; main();
Editor is loading...