Spaces:
Sleeping
Sleeping
Download server.js from YUFI-API/HDRezkaApi: direct link, hf CLI and curl.
- Browser
- Download file 1.59 kB
-
https://huggingface.co/spaces/YUFI-API/HDRezkaApi/resolve/main/server.js
- Command line
-
hf download hf://spaces/YUFI-API/HDRezkaApi/server.js
-
curl -L -o server.js https://huggingface.co/spaces/YUFI-API/HDRezkaApi/resolve/main/server.js
1.59 kB
| const express = require('express'); | |
| const axios = require('axios'); | |
| const cheerio = require('cheerio'); | |
| const app = express(); | |
| app.use(express.json()); | |
| const parsePage = async (url) => { | |
| const response = await axios.get(url); | |
| const html = response.data; | |
| const $ = cheerio.load(html); | |
| const parsedResults = []; | |
| $('.b-content__inline_item').each((index, element) => { | |
| const titleElement = $(element).find('.b-content__inline_item-link a'); | |
| const title = titleElement.text().trim(); | |
| const pageUrl = titleElement.attr('href'); | |
| const imageUrl = $(element).find('.b-content__inline_item-cover a img').attr('src'); | |
| parsedResults.push({ | |
| title: title, | |
| imageUrl: imageUrl, | |
| pageUrl: pageUrl, | |
| }); | |
| }); | |
| return parsedResults; | |
| }; | |
| app.get('/parse', async (req, res) => { | |
| try { | |
| const baseUrl = 'https://hdrezka180maa.org/animation'; | |
| let currentPage = 1; | |
| let hasMorePages = true; | |
| const allResults = []; | |
| while (hasMorePages) { | |
| const pageUrl = currentPage === 1 ? baseUrl : `${baseUrl}/page/${currentPage}/`; | |
| const results = await parsePage(pageUrl); | |
| if (results.length === 0) { | |
| hasMorePages = false; | |
| } else { | |
| allResults.push(...results); | |
| currentPage++; | |
| } | |
| } | |
| res.json(allResults); | |
| } catch (error) { | |
| console.error(error); | |
| res.status(500).json({ error: 'Произошла ошибка сервера при парсинге.' }); | |
| } | |
| }); | |
| const port = 7860; | |
| app.listen(port, () => { | |
| console.log(`Сервер запущен на порту ${port}`); | |
| }); |