fix(scraper): verify complete article evidence (#40)
This commit is contained in:
@ -257,7 +257,8 @@ async function scrapeBloombergViaPuppeteer(username, password, enrichment) {
|
||||
options.signal.addEventListener('abort', close, { once: true })
|
||||
try {
|
||||
if (options.signal.aborted) throw new Error('article expired')
|
||||
await articlePage.goto(url, { waitUntil: 'domcontentloaded', timeout: options.timeoutMs })
|
||||
const navigation = await articlePage.goto(url, { waitUntil: 'domcontentloaded', timeout: options.timeoutMs })
|
||||
if (!navigation || navigation.status() !== 200) throw new Error('article response unavailable')
|
||||
if (canonicalURL(articlePage.url()) !== canonicalURL(url)) throw new Error('article association unavailable')
|
||||
return await articlePage.content()
|
||||
} finally {
|
||||
@ -341,7 +342,7 @@ app.post('/bloomberg/enrich', async (req, res) => {
|
||||
const { username, password, urls } = req.body || {}
|
||||
if (!username || !password || !Array.isArray(urls) || urls.some(url => typeof url !== 'string')) return res.status(400).json({ error: 'invalid enrichment request' })
|
||||
if (!urls.length) return res.json({ articles: [] })
|
||||
const empty = () => urls.map(url => ({ url, content: '', published_at: null, content_truncated: false }))
|
||||
const empty = () => urls.map(url => ({ url, content: '', published_at: null, content_truncated: false, content_state: 'unavailable' }))
|
||||
if (!urls.some(url => canonicalURL(url))) return res.json({ articles: empty() })
|
||||
const controller = new AbortController()
|
||||
const deadline = Date.now() + TOTAL_TIMEOUT_MS
|
||||
@ -352,9 +353,9 @@ app.post('/bloomberg/enrich', async (req, res) => {
|
||||
const onClose = () => { if (!res.writableEnded) stop() }
|
||||
res.once?.('close', onClose)
|
||||
try {
|
||||
const operation = BYPARR_URL
|
||||
? enrichArticles(urls, async (url, options) => (await byparrFetch(url, true, options)).html, { signal: controller.signal })
|
||||
: scrapeBloombergViaPuppeteer(username, password, { urls, signal: controller.signal, deadline })
|
||||
// Section discovery still uses Byparr. Article bodies require the existing
|
||||
// authenticated browser session, with no anonymous transport fallback.
|
||||
const operation = scrapeBloombergViaPuppeteer(username, password, { urls, signal: controller.signal, deadline })
|
||||
const articles = await Promise.race([operation.catch(empty), expired])
|
||||
if (!res.destroyed) res.json({ articles })
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user