
Hacker News Data Scraper
- epctex/hackernews-scraper
- Modified
- Users 47
- Runs 2.8k
- Created by
epctex
Extract Y Combinator's Hacker News based on any search criteria. Crawl the front page, Show HN, Ask HN, news, job listings, and historical data. Get links, titles, comments, ratings, and more!
To run the code examples, you need to have an Apify account. Replace <YOUR_API_TOKEN> in the code with your API token. For a more detailed explanation, please read about running Actors via the API in Apify Docs.
import { ApifyClient } from 'apify-client';
// Initialize the ApifyClient with API token
const client = new ApifyClient({
token: '<YOUR_API_TOKEN>',
});
// Prepare Actor input
const input = {
"startUrls": [
{
"url": "https://news.ycombinator.com/front"
},
{
"url": "https://news.ycombinator.com/show"
},
{
"url": "https://news.ycombinator.com/jobs"
},
{
"url": "https://news.ycombinator.com"
},
{
"url": "https://news.ycombinator.com/item?id=26566373"
}
],
"maxItems": 50,
"endPage": 1,
"extendOutputFunction": ($) => { return {} },
"proxy": {
"useApifyProxy": true
}
};
(async () => {
// Run the Actor and wait for it to finish
const run = await client.actor("epctex/hackernews-scraper").call(input);
// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
console.dir(item);
});
})();