44
55import TurndownService from 'turndown' ;
66import { gfm } from 'turndown-plugin-gfm' ;
7- import * as cheerio from 'cheerio' ;
7+ import { load } from 'cheerio' ;
88import type { CheerioAPI } from 'cheerio' ;
99import { ExtractionSchema , ScrapedData } from './types' ;
1010
@@ -35,7 +35,7 @@ export class DataExtractor {
3535 * Extract data from HTML content
3636 */
3737 extract ( html : string , url : string , extractImages : boolean = true ) : ScrapedData {
38- const $ = cheerio . load ( html || '' ) ;
38+ const $ = load ( html || '' ) ;
3939
4040 const data : ScrapedData = {
4141 url,
@@ -74,7 +74,7 @@ export class DataExtractor {
7474 // If no custom schema or it didn't work, use default extraction
7575 if ( ! extractedContent || extractedContent . trim ( ) . length < 50 ) {
7676 // Work with a fresh copy of the HTML to avoid modifying the original
77- const $fresh = cheerio . load ( html ) ;
77+ const $fresh = load ( html ) ;
7878
7979 // Remove scripts, styles, noscript first
8080 $fresh ( 'script, style, noscript' ) . remove ( ) ;
@@ -148,7 +148,7 @@ export class DataExtractor {
148148
149149 // Ensure we have content - if still empty, use body as last resort
150150 if ( ! extractedContent || extractedContent . trim ( ) . length === 0 ) {
151- const $fallback = cheerio . load ( html ) ;
151+ const $fallback = load ( html ) ;
152152 $fallback ( 'script, style, noscript' ) . remove ( ) ;
153153 const body = $fallback ( 'body' ) ;
154154 if ( body . length > 0 ) {
@@ -175,7 +175,7 @@ export class DataExtractor {
175175 if ( extractedContent && extractedContent . trim ( ) . length > 0 ) {
176176 data . content = extractedContent ;
177177 try {
178- const content$ = cheerio . load ( extractedContent ) ;
178+ const content$ = load ( extractedContent ) ;
179179 content$ ( 'script, style, noscript' ) . remove ( ) ;
180180 this . removeNoise ( content$ ) ;
181181 // Remove nav/header/footer/ads that may be direct siblings of main content
0 commit comments