Newer
Older
TelosDB / tools / gemini-rag-tool / utils / scraper.mjs
@楽曲作りまくりおじさん 楽曲作りまくりおじさん 20 hours ago 486 bytes Refactor: reorganization of root and source directories and fix Error 1412
import axios from 'axios';
import * as cheerio from 'cheerio';

export async function scrapeText(url) {
    try {
        const response = await axios.get(url, {
            timeout: 5000,
            headers: { 'User-Agent': 'Mozilla/5.0' }
        });
        const $ = cheerio.load(response.data);
        $('script, style, nav, footer, header').remove();
        return $('body').text().replace(/\s+/g, ' ').trim().substring(0, 3000);
    } catch (err) {
        return '';
    }
}