|
@ -273,38 +273,36 @@ export class ManualService implements DataProviderInterface { |
|
|
private async scrape( |
|
|
private async scrape( |
|
|
scraperConfiguration: ScraperConfiguration |
|
|
scraperConfiguration: ScraperConfiguration |
|
|
): Promise<number> { |
|
|
): Promise<number> { |
|
|
try { |
|
|
let locale = scraperConfiguration.locale; |
|
|
let locale = scraperConfiguration.locale; |
|
|
|
|
|
const response = await fetch(scraperConfiguration.url, { |
|
|
|
|
|
headers: scraperConfiguration.headers as HeadersInit, |
|
|
|
|
|
signal: AbortSignal.timeout( |
|
|
|
|
|
this.configurationService.get('REQUEST_TIMEOUT') |
|
|
|
|
|
) |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (response.headers['content-type'].includes('application/json')) { |
|
|
const response = await fetch(scraperConfiguration.url, { |
|
|
const data = await response.json(); |
|
|
headers: scraperConfiguration.headers as HeadersInit, |
|
|
const value = String( |
|
|
signal: AbortSignal.timeout( |
|
|
jsonpath.query(data, scraperConfiguration.selector)[0] |
|
|
this.configurationService.get('REQUEST_TIMEOUT') |
|
|
); |
|
|
) |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
return extractNumberFromString({ locale, value }); |
|
|
if (response.headers['content-type']?.includes('application/json')) { |
|
|
} else { |
|
|
const data = await response.json(); |
|
|
const $ = cheerio.load(await response.text()); |
|
|
|
|
|
|
|
|
|
|
|
if (!locale) { |
|
|
const value = String( |
|
|
try { |
|
|
jsonpath.query(data, scraperConfiguration.selector)[0] |
|
|
locale = $('html').attr('lang'); |
|
|
); |
|
|
} catch {} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return extractNumberFromString({ |
|
|
return extractNumberFromString({ locale, value }); |
|
|
locale, |
|
|
} else { |
|
|
value: $(scraperConfiguration.selector).first().text() |
|
|
const $ = cheerio.load(await response.text()); |
|
|
}); |
|
|
|
|
|
|
|
|
if (!locale) { |
|
|
|
|
|
try { |
|
|
|
|
|
locale = $('html').attr('lang'); |
|
|
|
|
|
} catch {} |
|
|
} |
|
|
} |
|
|
} catch (error) { |
|
|
|
|
|
throw error; |
|
|
return extractNumberFromString({ |
|
|
|
|
|
locale, |
|
|
|
|
|
value: $(scraperConfiguration.selector).first().text() |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|