Actor picture

Smart Article Extractor

lukaskrivka/article-extractor-smart

Article Extractor scrapes detailed data from all articles on any website. It automatically recognizes what page is an article. It can be used for extracting news from BBC, CNN, Bloomberg, and other popular news websites.

Author's avatarLukáš Křivka
  • Modified
  • Users354
  • Runs48,129
Actor picture

Smart Article Extractor

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.

const { ApifyClient } = require('apify-client');

// Initialize the ApifyClient with API token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare actor input
const input = {
    "isUrlArticleDefinition": {
        "minDashes": 4,
        "hasDate": true,
        "linkIncludes": [
            "article",
            "storyid",
            "?p=",
            "id=",
            "/fpss/track",
            ".html",
            "/content/"
        ]
    },
    "proxyConfiguration": {
        "useApifyProxy": true
    },
    "extendOutputFunction": ($) => {
        const result = {};
        // Uncomment to add a title to the output
        // result.pageTitle = $('title').text().trim();
    
        return result;
    }
};

(async () => {
    // Run the actor and wait for it to finish
    const run = await client.actor("lukaskrivka/article-extractor-smart").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);
    });
})();