NPM Package

License

Installation

Install the package using npm or yarn:

# Using npm
npm i scrapegraph-js

# Using yarn
yarn add scrapegraph-js

Features

  • AI-Powered Extraction: Smart web scraping with artificial intelligence
  • Async by Design: Fully asynchronous architecture
  • Type Safety: Built-in TypeScript support with Zod schemas
  • Production Ready: Automatic retries and detailed logging
  • Developer Friendly: Comprehensive error handling

Quick Start

Basic example

Store your API keys securely in environment variables. Use .env files and libraries like dotenv to load them into your app.

import { smartScraper } from 'scrapegraph-js';
import 'dotenv/config';

// Initialize variables
const apiKey = process.env.SGAI_APIKEY; // Set your API key as an environment variable
const websiteUrl = 'https://example.com';
const prompt = 'What does the company do?';

try {
  const response = await smartScraper(apiKey, websiteUrl, prompt); // call SmartScraper function
  console.log(response.result);
} catch (error) {
  console.error('Error:', error);
}
;

Services

SmartScraper

Extract specific information from any webpage using AI:

const response = await smartScraper(
  apiKey,
  'https://example.com',
  'Extract the main content'
);

Parameters

ParameterTypeRequiredDescription
apiKeystringYesThe ScrapeGraph API Key.
websiteUrlstringYesThe URL of the webpage that needs to be scraped.
promptstringYesA textual description of what you want to achieve.
schemaobjectNoThe Pydantic or Zod object that describes the structure and format of the response.

SearchScraper

Search and extract information from multiple web sources using AI:


const response = await searchScraper(
  apiKey,
  'Find the best restaurants in San Francisco',
);

Parameters

ParameterTypeRequiredDescription
apiKeystringYesThe ScrapeGraph API Key.
promptstringYesA textual description of what you want to achieve.
schemaobjectNoThe Pydantic or Zod object that describes the structure and format of the response

Markdownify

Convert any webpage into clean, formatted markdown:

const response = await markdownify(
  apiKey,
  'https://example.com'
);

Parameters

ParameterTypeRequiredDescription
apiKeystringYesThe ScrapeGraph API Key.
websiteUrlstringYesThe URL of the webpage to convert to markdown.

API Credits

Check your available API credits:

import { getCredits } from 'scrapegraph-js';

try {
  const credits = await getCredits(apiKey);
  console.log('Available credits:', credits);
} catch (error) {
  console.error('Error fetching credits:', error);
}

Feedback

Help us improve by submitting feedback programmatically:

import { sendFeedback } from 'scrapegraph-js';

try {
  await sendFeedback(
    apiKey,
    'request-id',
    5,
    'Great results!'
  );
} catch (error) {
  console.error('Error sending feedback:', error);
}

Support