From 3b834919aeb5f67401f0abcd99d16f8956576c80 Mon Sep 17 00:00:00 2001 From: DPende Date: Tue, 11 Mar 2025 22:12:42 +0100 Subject: [PATCH 1/2] docs: added parameters detail for every functionality --- sdks/javascript.mdx | 63 +++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/sdks/javascript.mdx b/sdks/javascript.mdx index a667a49..94eae2b 100644 --- a/sdks/javascript.mdx +++ b/sdks/javascript.mdx @@ -41,27 +41,30 @@ yarn add scrapegraph-js ## Quick Start -Initialize with your API key: +### Basic example + + +Store your API keys securely in environment variables. Use `.env` files and libraries like `dotenv` to load them into your app. + ```javascript import { smartScraper } from 'scrapegraph-js'; +import 'dotenv/config'; -const apiKey = process.env.SGAI_APIKEY; +// Initialize variables +const apiKey = process.env.SGAI_APIKEY; // Set your API key as an environment variable const websiteUrl = 'https://example.com'; -const prompt = 'Extract the main heading and description'; +const prompt = 'What does the company do?'; try { - const response = await smartScraper(apiKey, websiteUrl, prompt); + const response = await smartScraper(apiKey, websiteUrl, prompt); // call SmartScraper function console.log(response.result); } catch (error) { console.error('Error:', error); } +; ``` - -Store your API keys securely in environment variables. Use `.env` files and libraries like `dotenv` to load them into your app. - - ## Services ### SmartScraper @@ -76,10 +79,19 @@ const response = await smartScraper( ); ``` +#### Parameters + +| Parameter | Type | Required | Description | +|-----------|------|----------|-------------| +| apiKey | string | Yes | The ScrapeGraph API Key. | +| websiteUrl | string | Yes | The URL of the webpage that needs to be scraped. | +| prompt | string | Yes | A textual description of what you want to achieve. | +| schema | object | No | The Pydantic or Zod object that describes the structure and format of the response. | + Define a simple schema using Zod: -```typescript +```javascript import { z } from 'zod'; const ArticleSchema = z.object({ @@ -108,7 +120,7 @@ console.log(`Published: ${response.result.publishDate}`); Define a complex schema for nested data structures: -```typescript +```javascript import { z } from 'zod'; const EmployeeSchema = z.object({ @@ -169,10 +181,18 @@ const response = await searchScraper( ); ``` +#### Parameters + +| Parameter | Type | Required | Description | +|-----------|------|----------|-------------| +| apiKey | string | Yes | The ScrapeGraph API Key. | +| prompt | string | Yes | A textual description of what you want to achieve. | +| schema | object | No | The Pydantic or Zod object that describes the structure and format of the response | + Define a simple schema using Zod: -```typescript +```javascript import { z } from 'zod'; const ArticleSchema = z.object({ @@ -199,7 +219,7 @@ console.log(`Published: ${response.result.publishDate}`); Define a complex schema for nested data structures: -```typescript +```javascript import { z } from 'zod'; const EmployeeSchema = z.object({ @@ -230,19 +250,6 @@ const response = await searchScraper( 'Find the best restaurants in San Francisco', RestaurantSchema ); - - - -// Access nested data -console.log(`Restaurant: ${response.result.name}`); -console.log('\nAddress:'); -response.result.address.forEach(address => { - console.log(`- ${address}`); -}); - - -console.log('\nRating:'); -console.log(`- ${response.result.rating}`); ``` @@ -258,6 +265,12 @@ const response = await markdownify( 'https://example.com' ); ``` +#### Parameters + +| Parameter | Type | Required | Description | +|-----------|------|----------|-------------| +| apiKey | string | Yes | The ScrapeGraph API Key. | +| websiteUrl | string | Yes | The URL of the webpage to convert to markdown. | ## API Credits From 563d00818e65cb7deb425e20c5e6becaf5fb835c Mon Sep 17 00:00:00 2001 From: DPende Date: Tue, 11 Mar 2025 22:14:26 +0100 Subject: [PATCH 2/2] fix: fixed all documentation --- services/markdownify.mdx | 173 +++++----------------- services/searchscraper.mdx | 248 ++++++------------------------- services/smartscraper.mdx | 289 +++++++------------------------------ 3 files changed, 132 insertions(+), 578 deletions(-) diff --git a/services/markdownify.mdx b/services/markdownify.mdx index 57c71b5..f7ee204 100644 --- a/services/markdownify.mdx +++ b/services/markdownify.mdx @@ -33,23 +33,18 @@ response = client.markdownify( ``` ```javascript JavaScript -import { Client } from 'scrapegraph-js'; +import { markdownify } from 'scrapegraph-js'; -// Initialize the client -const sgai_client = new Client("your-api-key"); +const apiKey = 'your-api-key'; +const url = 'https://scrapegraphai.com/'; try { - const response = await sgai_client.markdownify({ - websiteUrl: "https://example.com" - }); - - console.log('Request ID:', response.requestId); - console.log('Result:', response.result); + const response = await markdownify(apiKey, url); + console.log(response); } catch (error) { console.error(error); -} finally { - sgai_client.close(); } + ``` ```bash cURL @@ -65,6 +60,13 @@ curl -X 'POST' \ +#### Parameters + +| Parameter | Type | Required | Description | +|-----------|------|----------|-------------| +| apiKey | string | Yes | The ScrapeGraph API Key. | +| websiteUrl | string | Yes | The URL of the webpage to convert to markdown. | + Get your API key from the [dashboard](https://dashboard.scrapegraphai.com) @@ -128,152 +130,45 @@ The response includes: Want to learn more about our AI-powered scraping technology? Visit our [main website](https://scrapegraphai.com) to discover how we're revolutionizing web data extraction. -## Advanced Usage - -### Request Helper Function - -The `getMarkdownifyRequest` function helps create properly formatted request objects for the Markdownify service: - -```javascript -import { getMarkdownifyRequest } from 'scrapegraph-js'; +## Other Functionality -const request = getMarkdownifyRequest({ - websiteUrl: "https://example.com/article", - headers: { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" - } -}); -``` +### Retrieve a previous request -#### Parameters +If you know the response id of a previous request you made, you can retrieve all the information. -| Parameter | Type | Required | Description | -|-----------|------|----------|-------------| -| websiteUrl | string | Yes | The URL of the webpage to convert to markdown. | -| headers | object | No | Custom headers for the request (e.g., User-Agent, cookies). | - -#### Return Value - -Returns an object with the following structure: + -```typescript -{ - request_id: string; - status: "queued" | "processing" | "completed" | "failed"; - website_url: string; - result?: string | null; - error: string; -} +```python Python +// TODO ``` -#### Error Handling +```javascript JavaScript +import { getMarkdownifyRequest } from 'scrapegraph-js'; -The function includes built-in error handling for common scenarios: +const apiKey = 'your_api_key'; +const requestId = 'ID_of_previous_request'; -```javascript try { - const request = getMarkdownifyRequest({ - websiteUrl: "https://example.com/article" - }); + const requestInfo = await getMarkdownifyRequest(apiKey, requestId); + console.log(requestInfo); } catch (error) { - if (error.code === 'INVALID_URL') { - console.error('The provided URL is not valid'); - } else if (error.code === 'MISSING_REQUIRED') { - console.error('Required parameters are missing'); - } else { - console.error('An unexpected error occurred:', error); - } + console.error(error); } ``` -#### Advanced Examples - -##### Using Custom Headers - -```javascript -const request = getMarkdownifyRequest({ - websiteUrl: "https://example.com/article", - headers: { - "User-Agent": "Custom User Agent", - "Accept-Language": "en-US,en;q=0.9", - "Cookie": "session=abc123; user=john", - "Authorization": "Bearer your-auth-token" - } -}); -``` - -##### Handling Dynamic Content - -For websites with dynamic content, you might need to adjust the request: - -```javascript -const request = getMarkdownifyRequest({ - websiteUrl: "https://example.com/dynamic-content", - headers: { - // Headers to handle dynamic content - "X-Requested-With": "XMLHttpRequest", - "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9", - // Add any required session cookies - "Cookie": "dynamicContent=enabled; sessionId=xyz789" - } -}); -``` - -#### Best Practices - -1. **URL Validation** - - Always validate URLs before making requests - - Ensure URLs use HTTPS when possible - - Handle URL encoding properly - -```javascript -import { isValidUrl } from 'scrapegraph-js/utils'; - -const url = "https://example.com/article with spaces"; -const encodedUrl = encodeURI(url); - -if (isValidUrl(encodedUrl)) { - const request = getMarkdownifyRequest({ websiteUrl: encodedUrl }); -} +```bash cURL +// TODO ``` -2. **Header Management** - - Use appropriate User-Agent strings - - Include necessary cookies for authenticated content - - Set proper Accept headers - -3. **Error Recovery** - - Implement retry logic for transient failures - - Cache successful responses when appropriate - - Log errors for debugging - -```javascript -import { getMarkdownifyRequest, retry } from 'scrapegraph-js'; - -const makeRequest = retry(async () => { - const request = await getMarkdownifyRequest({ - websiteUrl: "https://example.com/article" - }); - return request; -}, { - retries: 3, - backoff: true -}); -``` + -4. **Performance Optimization** - - Batch requests when possible - - Use caching strategies - - Monitor API usage +#### Parameters -```javascript -import { cache } from 'scrapegraph-js/utils'; +| Parameter | Type | Required | Description | +|-----------|------|----------|-------------| +| apiKey | string | Yes | The ScrapeGraph API Key. | +| requestId | string | Yes | The request ID associated with the output of a previous searchScraper request. | -const cachedRequest = cache(getMarkdownifyRequest, { - ttl: 3600, // Cache for 1 hour - maxSize: 100 // Cache up to 100 requests -}); -``` ### Async Support diff --git a/services/searchscraper.mdx b/services/searchscraper.mdx index 867e8f3..78a1680 100644 --- a/services/searchscraper.mdx +++ b/services/searchscraper.mdx @@ -33,22 +33,16 @@ response = client.searchscraper( ``` ```javascript JavaScript -import { Client } from 'scrapegraph-js'; +import { searchScraper } from 'scrapegraph-js'; -// Initialize the client -const sgai_client = new Client("your-api-key"); +const apiKey = 'your-api-key'; +const prompt = 'What is the latest version of Python and what are its main features?'; try { - const response = await sgai_client.searchscraper({ - userPrompt: "Search for information" - }); - - console.log('Request ID:', response.requestId); - console.log('Result:', response.result); + const response = await searchScraper(apiKey, prompt); + console.log(response); } catch (error) { console.error(error); -} finally { - sgai_client.close(); } ``` @@ -65,6 +59,14 @@ curl -X 'POST' \ +#### Parameters + +| Parameter | Type | Required | Description | +|-----------|------|----------|-------------| +| apiKey | string | Yes | The ScrapeGraph API Key. | +| prompt | string | Yes | A textual description of what you want to achieve. | +| schema | object | No | The Pydantic or Zod object that describes the structure and format of the response | + Get your API key from the [dashboard](https://dashboard.scrapegraphai.com) @@ -193,211 +195,45 @@ The response includes: Want to learn more about our AI-powered search technology? Visit our [main website](https://scrapegraphai.com) to discover how we're revolutionizing web research. -## Advanced Usage - -### Request Helper Function - -The `getSearchScraperRequest` function helps create properly formatted request objects for the SearchScraper service: +## Other Functionality -```javascript -import { getSearchScraperRequest } from 'scrapegraph-js'; - -const request = getSearchScraperRequest({ - userPrompt: "What is the latest version of Python and its main features?", - outputSchema: { - version: { type: "string" }, - release_date: { type: "string" }, - major_features: { type: "array", items: { type: "string" } } - } -}); -``` +### Retrieve a previous request -#### Parameters - -| Parameter | Type | Required | Description | -|-----------|------|----------|-------------| -| userPrompt | string | Yes | The search query or question to answer. | -| headers | object | No | Custom headers for the request. | -| outputSchema | object | No | Schema defining the structure of the search results. | +If you know the response id of a previous request you made, you can retrieve all the information. -#### Return Value - -Returns an object with the following structure: + -```typescript -{ - request_id: string; - status: "queued" | "processing" | "completed" | "failed"; - user_prompt: string; - result?: object | null; - reference_urls: string[]; - error: string; -} +```python Python +// TODO ``` -#### Error Handling +```javascript JavaScript +import { getSearchScraperRequest } from 'scrapegraph-js'; -The function includes comprehensive error handling: +const apiKey = 'your_api_key'; +const requestId = 'ID_of_previous_request'; -```javascript try { - const request = getSearchScraperRequest({ - userPrompt: "What are the latest AI chip developments?", - outputSchema: { - manufacturers: { type: "array" }, - technologies: { type: "object" } - } - }); + const requestInfo = await getSearchScraperRequest(apiKey, requestId); + console.log(requestInfo); } catch (error) { - if (error.code === 'INVALID_PROMPT') { - console.error('The search prompt is invalid or empty'); - } else if (error.code === 'SCHEMA_VALIDATION') { - console.error('The output schema is invalid:', error.details); - } else if (error.code === 'MISSING_REQUIRED') { - console.error('Required parameters are missing'); - } else { - console.error('An unexpected error occurred:', error); - } + console.error(error); } ``` -#### Advanced Examples - -##### Complex Search Queries - -```javascript -const request = getSearchScraperRequest({ - userPrompt: "Compare the top 3 cloud providers (AWS, Azure, GCP) focusing on ML services pricing and features", - outputSchema: { - providers: { - type: "array", - items: { - type: "object", - properties: { - name: { type: "string" }, - ml_services: { - type: "array", - items: { - type: "object", - properties: { - name: { type: "string" }, - pricing: { type: "string" }, - features: { type: "array", items: { type: "string" } } - } - } - } - } - } - }, - comparison_matrix: { type: "object" }, - recommendation: { type: "string" } - } -}); -``` - -##### Time-Sensitive Searches - -```javascript -const request = getSearchScraperRequest({ - userPrompt: "Latest cryptocurrency market trends in the past 24 hours", - headers: { - // Headers for real-time data sources - "Cache-Control": "no-cache", - "Pragma": "no-cache" - }, - outputSchema: { - timestamp: { type: "string" }, - trends: { type: "array" }, - market_summary: { type: "object" } - } -}); -``` - -#### Best Practices - -1. **Query Optimization** - - Be specific and clear in your prompts - - Include relevant context - - Use appropriate keywords - -```javascript -// Good prompt example -const request = getSearchScraperRequest({ - userPrompt: "Compare iPhone 15 Pro Max and Samsung S24 Ultra specifications, focusing on camera capabilities, battery life, and performance benchmarks" -}); - -// Less effective prompt -const badRequest = getSearchScraperRequest({ - userPrompt: "Compare phones" // Too vague -}); -``` - -2. **Schema Design** - - Start with essential fields - - Use appropriate data types - - Include field descriptions - - Handle nested data properly - -```javascript -const schema = { - comparison: { - type: "object", - properties: { - date: { type: "string", description: "Comparison date" }, - devices: { - type: "array", - items: { - type: "object", - properties: { - name: { type: "string" }, - specs: { type: "object" }, - pros: { type: "array" }, - cons: { type: "array" } - } - } - } - } - } -}; +```bash cURL +// TODO ``` -3. **Error Recovery** - - Implement retry logic - - Handle rate limits - - Cache results when appropriate - -```javascript -import { getSearchScraperRequest, retry } from 'scrapegraph-js'; - -const searchWithRetry = retry(async (prompt) => { - const request = await getSearchScraperRequest({ - userPrompt: prompt - }); - return request; -}, { - retries: 3, - backoff: { - initial: 1000, - multiplier: 2, - maxDelay: 10000 - } -}); -``` + -4. **Performance Optimization** - - Use caching for repeated searches - - Batch related queries - - Monitor API usage +#### Parameters -```javascript -import { cache } from 'scrapegraph-js/utils'; +| Parameter | Type | Required | Description | +|-----------|------|----------|-------------| +| apiKey | string | Yes | The ScrapeGraph API Key. | +| requestId | string | Yes | The request ID associated with the output of a previous searchScraper request. | -const cachedSearch = cache(getSearchScraperRequest, { - ttl: 1800, // Cache for 30 minutes - maxSize: 50, // Cache up to 50 requests - keyGenerator: (params) => params.userPrompt // Cache key based on prompt -}); -``` ### Custom Schema Example @@ -428,9 +264,13 @@ response = client.searchscraper( ) ``` -```typescript TypeScript +```typescript JavaScript +import { searchScraper } from 'scrapegraph-js'; import { z } from 'zod'; +const apiKey = "your_api_key"; +const prompt = 'What is the latest version of Python and what are its main features?'; + const CompanyProfile = z.object({ name: z.string().describe('Company name'), description: z.string().describe('Brief company description'), @@ -445,10 +285,12 @@ const CompanyProfile = z.object({ techStack: z.array(z.string()).describe('Technologies used by the company') }); -const response = await client.search({ - userPrompt: 'Find comprehensive information about OpenAI', - outputSchema: CompanyProfile -}); +try { + const response = await searchScraper(apiKey, prompt, schema); + console.log(response.result); +} catch (error) { + console.error(error); +} ``` diff --git a/services/smartscraper.mdx b/services/smartscraper.mdx index 25a61e5..5d07f25 100644 --- a/services/smartscraper.mdx +++ b/services/smartscraper.mdx @@ -34,23 +34,17 @@ response = client.smartscraper( ``` ```javascript JavaScript -import { Client } from 'scrapegraph-js'; +import { smartScraper } from 'scrapegraph-js'; -// Initialize the client -const sgai_client = new Client("your-api-key"); +const apiKey = 'your-api-key'; +const url = 'https://scrapegraphai.com'; +const prompt = 'What does the company do?'; try { - const response = await sgai_client.smartscraper({ - websiteUrl: "https://example-shop.com/products/456", - userPrompt: "Extract product details including name, price, availability, specifications, and customer ratings." - }); - - console.log('Request ID:', response.requestId); - console.log('Result:', response.result); + const response = await smartScraper(apiKey, url, prompt); + console.log(response); } catch (error) { console.error(error); -} finally { - sgai_client.close(); } ``` @@ -68,6 +62,16 @@ curl -X 'POST' \ +#### Parameters + +| Parameter | Type | Required | Description | +|-----------|------|----------|-------------| +| apiKey | string | Yes | The ScrapeGraph API Key. | +| websiteUrl | string | Yes | The URL of the webpage that needs to be scraped. | +| prompt | string | Yes | A textual description of what you want to achieve. | +| schema | object | No | The Pydantic or Zod object that describes the structure and format of the response. | + + Get your API key from the [dashboard](https://dashboard.scrapegraphai.com) @@ -187,235 +191,44 @@ When both `website_url` and `website_html` are provided, `website_html` takes pr Want to learn more about our AI-powered scraping technology? Visit our [main website](https://scrapegraphai.com) to discover how we're revolutionizing web data extraction. -## Advanced Usage - -### Request Helper Function - -The `getSmartScraperRequest` function helps create properly formatted request objects for the SmartScraper service: - -```javascript -import { getSmartScraperRequest } from 'scrapegraph-js'; - -const request = getSmartScraperRequest({ - websiteUrl: "https://example.com", - userPrompt: "Extract product details including name, price, and description", - headers: { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" - }, - outputSchema: { - name: { type: "string" }, - price: { type: "number" }, - description: { type: "string" } - } -}); -``` - -#### Parameters - -| Parameter | Type | Required | Description | -|-----------|------|----------|-------------| -| websiteUrl | string | Yes* | The URL of the website to scrape. Either websiteUrl or websiteHtml must be provided. | -| userPrompt | string | Yes | Natural language description of what data to extract. | -| websiteHtml | string | No | HTML content to process instead of fetching from URL. | -| headers | object | No | Custom headers for the request (e.g., User-Agent, cookies). | -| outputSchema | object | No | Schema defining the structure of the extracted data. | +## Other Functionality -\* Either websiteUrl or websiteHtml must be provided. +### Retrieve a previous request -#### Return Value +If you know the response id of a previous request you made, you can retrieve all the information. -Returns an object with the following structure: + -```typescript -{ - request_id: string; - status: "queued" | "processing" | "completed" | "failed"; - website_url?: string; - user_prompt: string; - result?: object | null; - error: string; -} +```python Python +// TODO ``` -#### Error Handling +```javascript JavaScript +import { getSmartScraperRequest } from 'scrapegraph-js'; -The function includes robust error handling for various scenarios: +const apiKey = 'your_api_key'; +const requestId = 'ID_of_previous_request'; -```javascript try { - const request = getSmartScraperRequest({ - websiteUrl: "https://example.com/products", - userPrompt: "Extract all product information" - }); + const requestInfo = await getSmartScraperRequest(apiKey, requestId); + console.log(requestInfo); } catch (error) { - switch (error.code) { - case 'INVALID_URL': - console.error('The provided URL is not valid'); - break; - case 'INVALID_HTML': - console.error('The provided HTML content is invalid'); - break; - case 'SCHEMA_VALIDATION': - console.error('Output schema validation failed:', error.details); - break; - case 'MISSING_REQUIRED': - console.error('Required parameters are missing'); - break; - default: - console.error('An unexpected error occurred:', error); - } -} -``` - -#### Advanced Examples - -##### E-commerce Product Extraction - -```javascript -const request = getSmartScraperRequest({ - websiteUrl: "https://example.com/products/category", - userPrompt: "Extract all products from this category page", - headers: { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", - "Accept-Language": "en-US,en;q=0.9", - "Cookie": "currency=USD; country=US" - }, - outputSchema: { - category: { type: "string" }, - products: { - type: "array", - items: { - type: "object", - properties: { - id: { type: "string" }, - name: { type: "string" }, - price: { type: "number" }, - currency: { type: "string" }, - availability: { type: "boolean" }, - variants: { - type: "array", - items: { - type: "object", - properties: { - size: { type: "string" }, - color: { type: "string" }, - stock: { type: "number" } - } - } - } - } - } - } - } -}); -``` - -##### Processing Dynamic Content - -```javascript -// First, get the dynamic content -const dynamicHtml = await fetchDynamicContent("https://example.com/spa"); - -const request = getSmartScraperRequest({ - websiteHtml: dynamicHtml, - userPrompt: "Extract the main content section", - headers: { - "X-Requested-With": "XMLHttpRequest", - "Accept": "application/json" - } -}); -``` - -#### Best Practices - -1. **Input Validation** - - Validate URLs and HTML content - - Check prompt quality and clarity - - Verify schema structure - -```javascript -import { validateInput } from 'scrapegraph-js/utils'; - -const { isValid, errors } = validateInput({ - url: "https://example.com", - html: "
content
", - prompt: "Extract data", - schema: { type: "object" } -}); - -if (!isValid) { - console.error('Validation errors:', errors); + console.error(error); } ``` -2. **HTML Content Handling** - - Clean and normalize HTML - - Handle encoding properly - - Remove unnecessary scripts - -```javascript -import { cleanHtml } from 'scrapegraph-js/utils'; - -const cleanedHtml = cleanHtml(rawHtml, { - removeScripts: true, - removeStyles: true, - normalizeWhitespace: true -}); - -const request = getSmartScraperRequest({ - websiteHtml: cleanedHtml, - userPrompt: "Extract the content" -}); -``` - -3. **Error Recovery** - - Implement retry logic - - Handle rate limiting - - Log errors for debugging - -```javascript -import { getSmartScraperRequest, retry } from 'scrapegraph-js'; - -const scrapeWithRetry = retry(async (url, prompt) => { - const request = await getSmartScraperRequest({ - websiteUrl: url, - userPrompt: prompt - }); - return request; -}, { - retries: 3, - backoff: { - initial: 1000, - multiplier: 2, - maxDelay: 10000 - }, - onRetry: (error, attempt) => { - console.log(`Retry attempt ${attempt} due to: ${error.message}`); - } -}); +```bash cURL +// TODO ``` -4. **Performance Optimization** - - Use caching strategies - - Batch similar requests - - Monitor resource usage - -```javascript -import { cache, batch } from 'scrapegraph-js/utils'; +
-// Cache requests -const cachedScraper = cache(getSmartScraperRequest, { - ttl: 3600, - maxSize: 100, - keyGenerator: (params) => `${params.websiteUrl}-${params.userPrompt}` -}); +#### Parameters -// Batch requests -const batchScraper = batch(getSmartScraperRequest, { - maxBatchSize: 10, - batchDelay: 1000 -}); -``` +| Parameter | Type | Required | Description | +|-----------|------|----------|-------------| +| apiKey | string | Yes | The ScrapeGraph API Key. | +| requestId | string | Yes | The request ID associated with the output of a previous smartScraper request. | ### Custom Schema Example @@ -439,22 +252,26 @@ response = client.smartscraper( ) ``` -```typescript TypeScript +```javascript JavaScript +import { smartScraper } from 'scrapegraph-js'; import { z } from 'zod'; -const ArticleSchema = z.object({ - title: z.string().describe('Article title'), - author: z.string().describe('Author name'), - content: z.string().describe('Main article content'), - publishDate: z.string().describe('Publication date') +const apiKey = 'your_api_key'; +const url = 'https://scrapegraphai.com/'; +const prompt = 'What does the company do? and '; + +const schema = z.object({ + title: z.string().describe('The title of the webpage'), + description: z.string().describe('The description of the webpage'), + summary: z.string().describe('A brief summary of the webpage'), }); -const response = await smartScraper( - apiKey, - 'https://example.com/article', - 'Extract the article information', - ArticleSchema -); +try { + const response = await smartScraper(apiKey, url, prompt, schema); + console.log(response.result); +} catch (error) { + console.error(error); +} ```