A practical example of a script exploring hackernews
.
Example Script:
let {newPage, end, except, extract, extractAndSave, store, runStore, waitFor} = __sandbox;
let {params, } = OPTIONS;
(async () => { try {
// -- START --
const page = await newPage()
console.log('navigating to url')
await page.goto(params.url)
const {authors, titles, points} = await page.extract('hn')
console.log('scraping url')
const storeBlob = titles.map((title, index) => {
return {
id: index,
title,
author: authors[index],
points: points[index]
}
})
console.log('saving to store')
await store.saveMany('hn-data', storeBlob)
// -- END --
end()
} catch(e) { except(e) } })();
Downloadable Hackernews Project
The given snippet:
newPage()
methodurl
keyhn
. This scraper in this context extracts the authors, titles and points from HN.hn-data