Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

928 B
Raw Blame
import type { Server } from 'node:http';

import type { CheerioCrawlingContext } from '@crawlee/cheerio';
import { CheerioCrawler } from '@crawlee/cheerio';

import { runExampleComServer } from '../shared/_helper.js';

let serverAddress = 'http://localhost:';
let port: number;
let server: Server;

beforeAll(async () => {
    [server, port] = await runExampleComServer();
    serverAddress += port;
});

afterAll(() => {
    server.close();
});

describe('CheerioCrawler - XML should be parsed correctly', () => {
    test('should parse XML', async () => {
        let value!: string;

        function handler({ $ }: CheerioCrawlingContext) {
            value = $('item').first().find('link').text();
        }

        const crawler = new CheerioCrawler({
            requestHandler: handler,
        });

        await crawler.run([`${serverAddress}/special/complex-xml`]);

        expect(value).toBeTruthy();
    });
});