scraping | summarize llm article | summarize all articles | Search

This code imports necessary modules for extracting content from a website, interacting with a web browser, and summarizing the extracted content. A function testExtractor is then defined, which uses Selenium to extract and summarize content from a webpage and returns the summary.

Run example

npm run import -- "test article summarizer"

test article summarizer

const extractArticle = importer.import("extract llm article")
const getClient = importer.import("selenium client")
const summerizeArticle = importer.import("summarize llm article")

async function testExtractor(startPage) {
  if (!startPage) {
    startPage = 'https://tsakraklides.com/2025/02/05/in-the-age-of-infinite-consumer-choice-the-only-choice-is-collapse/'
  }

  driver = await getClient()

  try {

    let result = await extractArticle(driver, startPage)

    driver.quit()

    let summary = await summerizeArticle(result)

    return summary
  } catch (e) {
    driver.quit()

    throw e
  }
}


module.exports = testExtractor

What the code could have been:

'use strict';

const { extractLlmArticle } = require('./extractLlmArticle');
const { seleniumClient } = require('./seleniumClient');
const { summarizeLlmArticle } = require('./summarizeLlmArticle');

/**
 * Extracts a summary from a given article using a Selenium client and returns it.
 * 
 * @param {string} startPage The starting page URL to extract from.
 * @param {Object} options Optional configuration for the client.
 * @returns {Promise} The extracted summary.
 */
async function testExtractor(startPage, options = {}) {
  // Set default start page if not provided
  if (!startPage) {
    startPage = 'https://tsakraklides.com/2025/02/05/in-the-age-of-infinite-consumer-choice-the-only-choice-is-collapse/';
  }

  // Initialize Selenium client
  const driver = await seleniumClient(options);

  try {
    // Extract article content
    const result = await extractLlmArticle(driver, startPage);

    // Clean up client
    await driver.quit();

    // Summarize extracted article
    const summary = await summarizeLlmArticle(result);

    return summary;
  } catch (e) {
    // Clean up client on error
    await driver.quit();

    // Re-throw error
    throw e;
  }
}

module.exports = testExtractor;

Code Breakdown

Importing Modules

const extractArticle = importer.import('extract llm article')
const getClient = importer.import('selenium client')
const summarizeArticle = importer.import('summarize llm article')

Test Extraction Function

async function testExtractor(startPage) {
  //...
}

Setting up Selenium Client

driver = await getClient()

Extracting and Summarizing Article

try {
  let result = await extractArticle(driver, startPage)
  driver.quit()
  let summary = await summarizeArticle(result)
  return summary
} catch (e) {
  driver.quit()
  throw e
}

Exporting the Function

module.exports = testExtractor