feat(generation): select articles in three passes
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
const { withPublicationDates } = require('./publication-date')
|
||||
const express = require('express')
|
||||
const cheerio = require('cheerio')
|
||||
const puppeteer = require('puppeteer-extra')
|
||||
@ -24,8 +25,8 @@ async function byparrRequest(body) {
|
||||
return resp.json()
|
||||
}
|
||||
|
||||
async function byparrFetch(url) {
|
||||
console.log('[byparr] GET', url)
|
||||
async function byparrFetch(url, quiet = false) {
|
||||
if (!quiet) console.log('[byparr] GET', url)
|
||||
const data = await byparrRequest({ cmd: 'request.get', url, maxTimeout: 60000 })
|
||||
const html = data.solution?.response
|
||||
if (!html) throw new Error(`byparr returned no HTML for ${url}`)
|
||||
@ -93,7 +94,7 @@ async function scrapeBloombergViaByparr(username, password) {
|
||||
}
|
||||
}
|
||||
|
||||
return articles
|
||||
return withPublicationDates(articles, async url => (await byparrFetch(url, true)).html)
|
||||
}
|
||||
|
||||
// ---------- Bloomberg scraping via Puppeteer (fallback, may be blocked) ----------
|
||||
@ -246,7 +247,10 @@ async function scrapeBloombergViaPuppeteer(username, password) {
|
||||
}
|
||||
}
|
||||
|
||||
return articles
|
||||
return await withPublicationDates(articles, async url => {
|
||||
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 })
|
||||
return page.content()
|
||||
})
|
||||
} finally {
|
||||
if (browser) await browser.close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user