Spaces:
Sleeping
Sleeping
const express = require('express'); | |
const axios = require('axios'); | |
const cheerio = require('cheerio'); | |
const app = express(); | |
app.use(express.json()); | |
app.get('/parse', async (req, res) => { | |
try { | |
// Запрос HTML-кода страницы | |
const response = await axios.get('https://hdrezka180maa.org/animation'); | |
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, | |
}); | |
}); | |
// Отправка результата | |
res.json(parsedResults); | |
} catch (error) { | |
console.error(error); | |
res.status(500).json({ error: 'Произошла ошибка сервера при парсинге.' }); | |
} | |
}); | |
const port = 7860; | |
app.listen(port, () => { | |
console.log(`Сервер запущен на порту ${port}`); | |
}); |