### Install Dependencies and Start Development Server Source: https://github.com/apify/apify-docs/blob/master/README.md This snippet shows how to clone the repository, install dependencies using pnpm, and start the development server. Ensure Node.js 22 and pnpm 10 are installed as prerequisites. ```bash git clone https://github.com/apify/apify-docs.git cd apify-docs pnpm install pnpm start ``` -------------------------------- ### Start Interactive Apify Setup Source: https://github.com/apify/apify-docs/blob/master/sources/platform/integrations/ai/openclaw.md Run the setup wizard to configure your Apify API key interactively. This is the recommended method. ```bash openclaw apify setup ``` -------------------------------- ### Install Dependencies and Start Development Server Source: https://github.com/apify/apify-docs/blob/master/CONTRIBUTING.md Installs project dependencies using pnpm and starts the Docusaurus development server for local documentation building. ```bash pnpm install pnpm start ``` -------------------------------- ### Install and Setup Apify Plugin for OpenClaw Source: https://github.com/apify/apify-docs/blob/master/sources/platform/integrations/ai/openclaw.md Install the Apify plugin for OpenClaw, run the setup wizard, and restart the gateway to enable the integration. ```bash openclaw plugins install @apify/apify-openclaw-plugin openclaw apify setup openclaw gateway restart ``` -------------------------------- ### Puppeteer Setup Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/puppeteer_playwright/executing_scripts/extracting_data.md Basic setup for launching Puppeteer, creating a new page, and navigating to a URL. Ensure Puppeteer is installed. ```javascript import puppeteer from 'puppeteer'; const browser = await puppeteer.launch({ headless: false }); const page = await browser.newPage(); await page.goto('https://demo-webstore.apify.org/search/on-sale'); // code will go here await page.waitForTimeout(10000); await browser.close(); ``` -------------------------------- ### Test Project Setup Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/scraping_basics_legacy/data_extraction/project_setup.md Create a main.js file and add this code to verify that the got-scraping and cheerio libraries are installed and imported correctly. Run with 'node main.js'. ```js import { gotScraping } from 'got-scraping'; import * as cheerio from 'cheerio'; console.log('it works!'); ``` -------------------------------- ### Run Python script to verify setup Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/scraping_basics_python/04_downloading_html.md Execute the main.py script to confirm that the Python environment and httpx installation are functional. ```text $ python main.py OK ``` -------------------------------- ### Verify Python and httpx setup Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/scraping_basics_python/04_downloading_html.md Create a main.py file with a simple print statement to verify that the Python environment and httpx installation are working correctly. ```python import httpx print("OK") ``` -------------------------------- ### Configure MCP Server for Minimal Setups Source: https://github.com/apify/apify-docs/blob/master/sources/platform/integrations/ai/mcp.md For minimal setups, specify only the required Actors in the server URL. This example includes an Instagram scraper and a Google search scraper. ```url https://mcp.apify.com?tools=apify/instagram-scraper,apify/google-search-scraper ``` -------------------------------- ### Project Setup with npm Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/api_scraping/graphql_scraping/custom_queries.md Initializes a new Node.js project and installs necessary packages: graphql-tag, puppeteer, and got-scraping. Run this command in your project's root directory. ```shell npm init -y && npm install graphql-tag puppeteer got-scraping ``` -------------------------------- ### Start a Simple Web Server with Express.js Source: https://github.com/apify/apify-docs/blob/master/sources/platform/actors/development/programming_interface/container_web_server.md This JavaScript snippet demonstrates how to start a basic Express.js web server within an Actor. It listens on the port specified by ACTOR_WEB_SERVER_PORT and responds to root requests. Ensure you have installed Express.js using 'npm install express'. The Actor is set to run for an hour. ```javascript // npm install express import { Actor } from 'apify'; import express from 'express'; await Actor.init(); const app = express(); const port = process.env.ACTOR_WEB_SERVER_PORT; app.get('/', (req, res) => { res.send('Hello world from Express app!'); }); app.listen(port, () => console.log(`Web server is listening and can be accessed at ${process.env.ACTOR_WEB_SERVER_URL}!`)); // Let the Actor run for an hour await new Promise((r) => setTimeout(r, 60 * 60 * 1000)); await Actor.exit(); ``` -------------------------------- ### Complete LangChain Integration Example Source: https://github.com/apify/apify-docs/blob/master/sources/platform/integrations/ai/langchain.md A full Python script combining all steps: imports, API key setup, Actor execution, index creation, and querying. Save this as a .py file to run. ```python import os from langchain.indexes import VectorstoreIndexCreator from langchain_apify import ApifyWrapper from langchain_core.documents import Document from langchain_core.vectorstores import InMemoryVectorStore from langchain_openai import ChatOpenAI from langchain_openai.embeddings import OpenAIEmbeddings os.environ["OPENAI_API_KEY"] = "Your OpenAI API key" os.environ["APIFY_API_TOKEN"] = "Your Apify API token" apify = ApifyWrapper() llm = ChatOpenAI(model="gpt-4o-mini") print("Call website content crawler ...") loader = apify.call_actor( actor_id="apify/website-content-crawler", run_input={"startUrls": [{"url": "https://docs.langchain.com/oss/python/langchain/quickstart"}], "maxCrawlPages": 10, "crawlerType": "cheerio"}, dataset_mapping_function=lambda item: Document(page_content=item["text"] or "", metadata={"source": item["url"]}), ) print("Compute embeddings...") index = VectorstoreIndexCreator( vectorstore_cls=InMemoryVectorStore, embedding=OpenAIEmbeddings() ).from_loaders([loader]) query = "What is LangChain?" result = index.query_with_sources(query, llm=llm) print("answer:", result["answer"]) print("source:", result["sources"]) ``` -------------------------------- ### Playwright Setup Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/puppeteer_playwright/executing_scripts/extracting_data.md Basic setup for launching Playwright, creating a new page, and navigating to a URL. Ensure Playwright is installed. ```javascript import { chromium } from 'playwright'; const browser = await chromium.launch({ headless: false }); const page = await browser.newPage(); await page.goto('https://demo-webstore.apify.org/search/on-sale'); // code will go here await page.waitForTimeout(10000); await browser.close(); ``` -------------------------------- ### Run Langflow Platform Source: https://github.com/apify/apify-docs/blob/master/sources/platform/integrations/ai/langflow.md Start the Langflow platform after installation. This command launches the local Langflow server, accessible via a web browser. ```bash uv run langflow run ``` -------------------------------- ### Start a Simple Web Server with Flask Source: https://github.com/apify/apify-docs/blob/master/sources/platform/actors/development/programming_interface/container_web_server.md This Python snippet shows how to set up a basic Flask web server inside an Actor. It defines a root route that returns a greeting and logs the public URL. Make sure to install Flask using 'pip install flask'. The server listens on the port provided by ACTOR_WEB_SERVER_PORT. ```python # pip install flask import asyncio import os from apify import Actor from apify_shared.consts import ActorEnvVars from flask import Flask async def main(): async with Actor: # Create a Flask app app = Flask(__name__) # Define a route @app.route('/') def hello_world(): return 'Hello world from Flask app!' # Log the public URL url = os.environ.get(ActorEnvVars.WEB_SERVER_URL) Actor.log.info(f'Web server is listening and can be accessed at {url}') # Start the web server port = os.environ.get(ActorEnvVars.WEB_SERVER_PORT) app.run(host='0.0.0.0', port=port) ``` -------------------------------- ### Example REST API Requests Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/api_scraping/index.md Demonstrates typical GET and POST requests to a REST API, including requests with query parameters. ```text GET https://api.example.com/users/123 GET https://api.example.com/comments/abc123?limit=100 POST https://api.example.com/orders ``` -------------------------------- ### Setup MITM Proxy and Certificates Source: https://github.com/apify/apify-docs/blob/master/sources/academy/tutorials/node_js/using_proxy_to_intercept_requests_puppeteer.md Sets up the http-mitm-proxy, configures NSS database for Chromium certificates, and adds the CA certificate. Requires certutil to be installed. ```javascript const { promisify } = require('util'); const { exec } = require('child_process'); const Proxy = require('http-mitm-proxy'); const Promise = require('bluebird'); const execPromise = promisify(exec); const wait = (timeout) => new Promise((resolve) => setTimeout(resolve, timeout)); const setupProxy = async (port) => { // Setup chromium certs directory // WARNING: this only works in debian docker images // modify it for any other use cases or local usage. await execPromise('mkdir -p $HOME/.pki/nssdb'); await execPromise('certutil -d sql:$HOME/.pki/nssdb -N'); const proxy = Proxy(); proxy.use(Proxy.wildcard); proxy.use(Proxy.gunzip); return new Promise((resolve, reject) => { proxy.listen({ port, silent: true }, (err) => { if (err) return reject(err); // Add CA certificate to chromium and return initialize proxy object execPromise('certutil -d sql:$HOME/.pki/nssdb -A -t "C,,," -n mitm-ca -i ./.http-mitm-proxy/certs/ca.pem') .then(() => resolve(proxy)) .catch(reject); }); }); }; ``` -------------------------------- ### Download HTML of a product listing page Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/scraping_basics_python/04_downloading_html.md Use the httpx library to make an HTTP GET request to a specified URL and print the HTML content of the response. Ensure the httpx library is installed. ```python import httpx url = "https://warehouse-theme-metal.myshopify.com/collections/sales" response = httpx.get(url) print(response.text) ``` -------------------------------- ### Run Actor and Get Dataset Items (Synchronous) Source: https://github.com/apify/apify-docs/blob/master/sources/platform/integrations/ai/x402.md This example demonstrates the three-step process to run an Actor synchronously and retrieve dataset items using the x402 payment protocol. It includes discovering payment requirements, signing the payment, and executing the Actor run. ```APIDOC ## Run Actor and Get Dataset Items (Synchronous) ### Description This operation allows you to run an Actor synchronously and retrieve its dataset items by directly integrating with the Apify REST API using the x402 payment protocol. It involves discovering payment requirements, signing the payment, and then executing the Actor run with the signed payment. ### Method POST ### Endpoint `https://api.apify.com/v2/actors//run-sync-get-dataset-items` ### Parameters #### Headers - **X-APIFY-PAYMENT-PROTOCOL** (string) - Required - Set to `X402` to indicate x402 payment. - **PAYMENT-SIGNATURE** (string) - Required - The base64-encoded signed payment payload obtained after signing. - **Content-Type** (string) - Required - Set to `application/json`. #### Path Parameters - **actor_name** (string) - Required - The name of the Actor to run. Replace `/` with `~` (e.g., `apify~instagram-post-scraper`). #### Request Body - **(dynamic)** (object) - Required - Actor input schema. Example: `{"username": ["natgeo"], "resultsLimit": 3}` ### Request Example ```bash # Step 1: Discover payment requirements (initial request without signature) curl -si \ -H "X-APIFY-PAYMENT-PROTOCOL: X402" \ "https://api.apify.com/v2/actors/apify~instagram-post-scraper/run-sync-get-dataset-items" # → HTTP 402 + PAYMENT-REQUIRED header value # Step 2: Sign the payment using mcpc (replace with the actual header value) # mcpc x402 sign # → outputs your base64 PAYMENT-SIGNATURE # Step 3: Run the Actor and get results (replace with your signature) curl -s \ -H "PAYMENT-SIGNATURE: " \ -H "Content-Type: application/json" \ -d '{"username": ["natgeo"], "resultsLimit": 3}' \ "https://api.apify.com/v2/actors/apify~instagram-post-scraper/run-sync-get-dataset-items" ``` ### Response #### Success Response (200) - **(array)** - JSON array containing the dataset items generated by the Actor run. ``` -------------------------------- ### Install Mastra and AI SDK Packages Source: https://github.com/apify/apify-docs/blob/master/sources/platform/integrations/ai/mastra.md Install the necessary packages for Mastra core, MCP client, and the AI SDK for OpenAI. Ensure Node.js is installed. ```bash npm install @mastra/core @mastra/mcp @ai-sdk/openai ``` -------------------------------- ### Dockerfile Start Command Source: https://github.com/apify/apify-docs/blob/master/sources/platform/actors/development/actor_definition/source_code.md Defines the command to start the Actor, executing the 'start' script from package.json. ```dockerfile CMD npm start --silent ``` -------------------------------- ### Launch Browser (Puppeteer) Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/puppeteer_playwright/browser.md Launches a Chromium browser instance using Puppeteer. This is a basic example to get started. ```javascript import puppeteer from 'puppeteer'; await puppeteer.launch(); console.log('launched!'); ``` -------------------------------- ### Launch Browser (Playwright) Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/puppeteer_playwright/browser.md Launches a Chromium browser instance using Playwright. This is a basic example to get started. ```javascript import { chromium } from 'playwright'; await chromium.launch(); console.log('launched!'); ``` -------------------------------- ### Get List of Keys with Prefix Source: https://github.com/apify/apify-docs/blob/master/sources/platform/actors/development/actor_definition/key_value_store_schema/index.md Filter keys by a specific prefix using the `prefix` parameter in the API request. This example retrieves keys starting with 'document-'. ```http GET https://api.apify.com/v2/key-value-stores/{storeId}/keys?prefix=document- ``` -------------------------------- ### Start Development Server for All Repositories Source: https://github.com/apify/apify-docs/blob/master/CONTRIBUTING.md Starts the development server for all Apify documentation repositories, enabling them to be served together. ```bash pnpm start:dev ``` -------------------------------- ### Set Start URL for Apify Store Source: https://github.com/apify/apify-docs/blob/master/sources/academy/tutorials/apify_scrapers/getting_started.md Define the initial URL for the scraper to begin crawling. This example sets the Apify Store as the starting point. ```text https://apify.com/store ``` -------------------------------- ### Full Example: Run Actor and Download Dataset Items (Node.js) Source: https://github.com/apify/apify-docs/blob/master/sources/academy/platform/getting_started/apify_client.md A complete Node.js example demonstrating how to initialize the ApifyClient, call an actor, retrieve its default dataset ID, download items, and log them. ```js // client.js import { ApifyClient } from 'apify-client'; const client = new ApifyClient({ token: 'YOUR_TOKEN', }); const run = await client.actor('YOUR_USERNAME/adding-actor').call({ num1: 4, num2: 2, }); const dataset = client.dataset(run.defaultDatasetId); const { items } = await dataset.listItems(); console.log(items); ``` -------------------------------- ### Full Example: Run Actor and Download Dataset Items (Python) Source: https://github.com/apify/apify-docs/blob/master/sources/academy/platform/getting_started/apify_client.md A complete Python example demonstrating how to initialize the ApifyClient, call an actor, retrieve its default dataset ID, download items, and print them. ```py # client.py from apify_client import ApifyClient client = ApifyClient(token='YOUR_TOKEN') actor = client.actor('YOUR_USERNAME/adding-actor').call(run_input={ 'num1': 4, 'num2': 2 }) dataset = client.dataset(run['defaultDatasetId']) items = dataset.list_items().items print(items) ``` -------------------------------- ### Example OpenAPI 3.x specification Source: https://github.com/apify/apify-docs/blob/master/sources/platform/actors/development/actor_definition/web_server_schema/index.md This is an example of an OpenAPI 3.x specification file that defines a simple GET endpoint for searching items. It includes parameter and response schema definitions. ```json { "openapi": "3.0.0", "info": { "title": "My API Actor", "version": "1.0.0" }, "paths": { "/search": { "get": { "summary": "Search for items", "parameters": [ { "name": "query", "in": "query", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Search results" } } } } } } ``` -------------------------------- ### Playwright Setup for Lazy-Loading Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/puppeteer_playwright/common_use_cases/paginating_through_results.md Basic Playwright setup to launch a browser, open a new page, and navigate to a URL with lazy-loading content. Use this as a starting point for scraping lazy-loaded results. ```javascript import { chromium } from 'playwright'; // Create an array where all scraped products will // be pushed to const products = []; const browser = await chromium.launch({ headless: false }); const page = await browser.newPage(); await page.goto('https://www.aboutyou.com/c/women/clothing-20204'); await browser.close(); ``` -------------------------------- ### Distributivity Example Source: https://github.com/apify/apify-docs/blob/master/sources/platform/storage/request_queue.md This example demonstrates how to get and use the same request queue in different Actor runs with different client keys. It shows how one run can lock requests and how another run attempts to access them. ```javascript import { Actor, ApifyClient } from 'apify'; await Actor.init(); const client = new ApifyClient({ token: 'MY-APIFY-TOKEN', }); // Waits for the first Actor to lock the requests. await new Promise((resolve) => setTimeout(resolve, 5000)); // Get the same request queue in different Actor run and with a different client key. const requestQueue = await client.requestQueues().getOrCreate('example-queue'); const requestQueueClient = client.requestQueue(requestQueue.id, { clientKey: 'requestqueuetwo', }); // Get all requests from the queue and check one locked by the first Actor. const requests = await requestQueueClient.listRequests(); const requestsLockedByAnotherRun = requests.items.filter((request) => request.lockByClient === 'requestqueueone'); const requestLockedByAnotherRunDetail = await requestQueueClient.getRequest( requestsLockedByAnotherRun[0].id, ); // Other clients cannot list and lock these requests; the listAndLockHead call returns other requests from the queue. const processingRequestsClientTwo = await requestQueueClient.listAndLockHead( { limit: 10, lockSecs: 60, }, ); const wasBothRunsLockedSameRequest = !!processingRequestsClientTwo.items.find( (request) => request.id === requestLockedByAnotherRunDetail.id, ); console.log(`Was the request locked by the first run locked by the second run? ${wasBothRunsLockedSameRequest}`); console.log(`Request locked until ${requestLockedByAnotherRunDetail?.lockExpiresAt}`); // Other clients cannot modify the lock; attempting to do so will throw an error. try { await requestQueueClient.prolongRequestLock( requestLockedByAnotherRunDetail.id, { lockSecs: 60 }, ); } catch (err) { // This will throw an error. } // Cleans up the queue. await requestQueueClient.delete(); await Actor.exit(); ``` -------------------------------- ### Start Development Server Source: https://github.com/apify/apify-docs/blob/master/GEMINI.md Starts the development server, which rebuilds API docs. Accessible on port 3000. ```bash pnpm start ``` -------------------------------- ### Basic Playwright Setup for Navigation Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/puppeteer_playwright/reading_intercepting_requests.md This snippet demonstrates the initial setup for Playwright to launch a browser, open a new page, and navigate to a specific URL. It's used as a starting point for intercepting network requests. ```javascript import { chromium } from 'playwright'; const browser = await chromium.launch({ headless: false }); const page = await browser.newPage(); // Our code will go here await page.goto('https://soundcloud.com/tiesto/following'); await page.waitForTimeout(10000); await browser.close(); ``` -------------------------------- ### Start Development Server Source: https://github.com/apify/apify-docs/blob/master/AGENTS.md Starts the development server, which rebuilds API docs and runs on port 3000. ```bash pnpm start # Dev server (rebuilds API docs, port 3000) ``` -------------------------------- ### E.g. and I.e. Formatting Examples Source: https://github.com/apify/apify-docs/blob/master/standards/grammar-rules.md Illustrates the correct comma usage before 'e.g.' and 'i.e.' and advises against starting sentences with them. ```text Use a runtime, e.g. Node.js ``` ```text For example, you can use Playwright ``` ```text That is, it runs on the server ``` -------------------------------- ### Install Dependencies Source: https://github.com/apify/apify-docs/blob/master/sources/academy/tutorials/node_js/dealing_with_dynamic_pages.md Command to initialize a new Node.js project and install the necessary 'crawlee' and 'cheerio' packages. ```shell # this command will initialize your project # and install the "crawlee" and "cheerio" packages npm init -y && npm i crawlee ``` -------------------------------- ### Scraped Product Offer Example Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/scraping_basics_legacy/challenge/index.md Example of the desired output format for each scraped product offer. Includes title, ASIN, URL, description, keyword, seller name, and offer price. ```json [ { "title": "Apple iPhone 6 a1549 16GB Space Gray Unlocked (Certified Refurbished)", "asin": "B07P6Y7954", "itemUrl": "https://www.amazon.com/Apple-iPhone-Unlocked-Certified-Refurbished/dp/B00YD547Q6/ref=sr_1_2?s=wireless&ie=UTF8&qid=1539772626&sr=1-2&keywords=iphone", "description": "What's in the box: Certified Refurbished iPhone 6 Space Gray 16GB Unlocked , USB Cable/Adapter. Comes in a Generic Box with a 1 Year Limited Warranty.", "keyword": "iphone", "sellerName": "Blutek Intl", "offer": "$162.97" }, { "title": "Apple iPhone 6 a1549 16GB Space Gray Unlocked (Certified Refurbished)", "asin": "B07P6Y7954", "itemUrl": "https://www.amazon.com/Apple-iPhone-Unlocked-Certified-Refurbished/dp/B00YD547Q6/ref=sr_1_2?s=wireless&ie=UTF8&qid=1539772626&sr=1-2&keywords=iphone", "description": "What's in the box: Certified Refurbished iPhone 6 Space Gray 16GB Unlocked , USB Cable/Adapter. Comes in a Generic Box with a 1 Year Limited Warranty.", "keyword": "iphone", "sellerName": "PLATINUM DEALS", "offer": "$169.98" }, { "...": "..." } ] ``` -------------------------------- ### Puppeteer Setup and Data Extraction Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/puppeteer_playwright/executing_scripts/extracting_data.md This snippet demonstrates setting up Puppeteer, navigating to a page, loading its content with Cheerio, and extracting product names and prices. ```javascript import puppeteer from 'puppeteer'; import { load } from 'cheerio'; const browser = await puppeteer.launch({ headless: false }); const page = await browser.newPage(); await page.goto('https://demo-webstore.apify.org/search/on-sale'); const $ = load(await page.content()); const productCards = Array.from($('a[class*="ProductCard_root"]')); const products = productCards.map((element) => { const card = $(element); const name = card.find('h3[class*="ProductCard_name"]').text(); const price = card.find('div[class*="ProductCard_price"]').text(); return { name, price, }; }); console.log(products); await browser.close(); ``` -------------------------------- ### Full Apify BeautifulSoupCrawler Example Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/scraping_basics_python/12_framework.md This is a complete example of a web scraper using Apify's BeautifulSoupCrawler. It includes default and specific handlers, enqueuing links, extracting product details including price and variants, and running the crawler on a starting URL. ```python import asyncio from crawlee.crawlers import BeautifulSoupCrawler, BeautifulSoupCrawlingContext async def main(): crawler = BeautifulSoupCrawler() @crawler.router.default_handler async def handle_listing(context: BeautifulSoupCrawlingContext): await context.enqueue_links(selector=".product-list a.product-item__title", label="DETAIL") @crawler.router.handler("DETAIL") async def handle_detail(context: BeautifulSoupCrawlingContext): price_text = ( context.soup .select_one(".product-form__info-content .price") .contents[-1] .strip() .replace("$", "") .replace(".", "") .replace(",", "") ) item = { "url": context.request.url, "title": context.soup.select_one(".product-meta__title").text.strip(), "vendor": context.soup.select_one(".product-meta__vendor").text.strip(), "price": int(price_text), "variant_name": None, } if variants := context.soup.select(".product-form__option.no-js option"): for variant in variants: print(item | parse_variant(variant)) else: print(item) await crawler.run(["https://warehouse-theme-metal.myshopify.com/collections/sales"]) def parse_variant(variant): text = variant.text.strip() name, price_text = text.split(" - ") price = int( price_text .replace("$", "") .replace(".", "") .replace(",", "") ) return {"variant_name": name, "price": price} if __name__ == '__main__': asyncio.run(main()) ``` -------------------------------- ### Build for Production Source: https://github.com/apify/apify-docs/blob/master/AGENTS.md Creates a production build of the documentation site, catching broken links and bad frontmatter. ```bash pnpm build # Production build (catches broken links, bad frontmatter) ``` -------------------------------- ### Front Matter Example: Tutorial Source: https://github.com/apify/apify-docs/blob/master/standards/content-standards.md Example of YAML front matter for a tutorial page, specifying title, description, sidebar position, and slug. ```yaml --- title: Build a web scraper description: Step-by-step guide to building your first web scraper with Apify and Playwright. sidebar_position: 1.0 slug: /academy/tutorials/web-scraper --- ``` -------------------------------- ### Example JSON Output Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/scraping_basics_javascript/08_saving_data.md This is an example of the structure and content of the 'products.json' file. ```json [{"title":"JBL Flip 4 Waterproof Portable Bluetooth Speaker","minPrice":7495,"price":7495},{"title":"Sony XBR-950G BRAVIA 4K HDR Ultra HD TV","minPrice":139800,"price":null},...] ``` -------------------------------- ### Basic CheerioCrawler Setup Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/scraping_basics_javascript/12_framework.md Initialize a CheerioCrawler and define a default handler to extract and log the title of a webpage. This is a starting point for scraping static HTML content. ```javascript import { CheerioCrawler } from 'crawlee'; const crawler = new CheerioCrawler(); crawler.router.addDefaultHandler(async ({ $, log }) => { const title = $('title').text().trim(); log.info(title); }); await crawler.run(['https://warehouse-theme-metal.myshopify.com/collections/sales']); ``` -------------------------------- ### Connect to MCP Connector in Python Source: https://github.com/apify/apify-docs/blob/master/sources/platform/integrations/ai/mcp-connectors/using-connectors-in-actors.md Installs necessary Python packages and shows how to connect to an MCP connector, list tools, and send a message using environment variables for proxy URL and API token. Uses httpx for HTTP requests. ```bash pip install mcp httpx apify ``` ```python import asyncio import os import httpx from apify import Actor from mcp import ClientSession from mcp.client.streamable_http import streamable_http_client async def main(): async with Actor: input_data = await Actor.get_input() connector_id = input_data['slack_connector'] proxy_url = os.environ['APIFY_MCP_PROXY_URL'] token = os.environ['APIFY_TOKEN'] async with httpx.AsyncClient( headers={"Authorization": f"Bearer {token}"}, ) as http_client: async with streamable_http_client( f"{proxy_url}/{connector_id}", http_client=http_client, ) as (read, write, _): async with ClientSession(read, write) as session: await session.initialize() tools = (await session.list_tools()).tools result = await session.call_tool( "send_message", arguments={ "channel": "#general", "text": "Hello from Apify!", }, ) asyncio.run(main()) ``` -------------------------------- ### Initialize and Get Input with Apify SDK (Node.js) Source: https://github.com/apify/apify-docs/blob/master/sources/academy/platform/deploying_your_code/inputs_outputs.md Initializes the Apify Actor and retrieves input data using the `Actor.getInput()` function. Ensure the `apify` package is installed. ```javascript import { Actor } from 'apify'; // We must initialize and exit the Actor. The rest of our code // goes in between these two. await Actor.init(); const input = await Actor.getInput(); console.log(input); await Actor.exit(); ``` -------------------------------- ### Basic BeautifulSoupCrawler Setup Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/scraping_basics_python/12_framework.md Initializes a BeautifulSoupCrawler and defines a default handler to extract and print the page title. This snippet is used to start a scraping process on a given URL. ```python import asyncio from crawlee.crawlers import BeautifulSoupCrawler, BeautifulSoupCrawlingContext async def main(): crawler = BeautifulSoupCrawler() @crawler.router.default_handler async def handle_listing(context: BeautifulSoupCrawlingContext): if title := context.soup.title: print(title.text.strip()) await crawler.run(["https://warehouse-theme-metal.myshopify.com/collections/sales"]) if __name__ == '__main__': asyncio.run(main()) ``` -------------------------------- ### Build Production Version Source: https://github.com/apify/apify-docs/blob/master/GEMINI.md Creates a production build of the documentation site. Catches broken links and bad frontmatter. ```bash pnpm build ``` -------------------------------- ### Install Scraping Libraries Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/scraping_basics_legacy/data_extraction/project_setup.md Install the got-scraping and cheerio libraries into your project using npm. got-scraping is for downloading HTML, and cheerio is for parsing it. ```shell npm install got-scraping cheerio ``` -------------------------------- ### Get Item Height for Scrolling Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/puppeteer_playwright/common_use_cases/paginating_through_results.md Grabs the client height of a result item element, which is used to determine scroll increments. This is a setup step before initiating the scrolling loop. ```javascript const itemHeight = await page.$eval('a[data-testid*="productTile"]', (elem) => elem.clientHeight); // Keep track of how many pixels have been scrolled down const totalScrolled = 0; ``` -------------------------------- ### Standard Settings Output Example Source: https://github.com/apify/apify-docs/blob/master/sources/platform/integrations/workflows-and-notifications/make/llm.md Example JSON output from the Standard Settings module, showing search query, crawl details, search result information, metadata, and extracted Markdown content. Useful for understanding the data structure returned by the module. ```json { "query": "web browser for RAG pipelines -site:reddit.com", "crawl": { "httpStatusCode": 200, "httpStatusMessage": "OK", "loadedAt": "2025-06-30T10:15:23.456Z", "uniqueKey": "https://example.com/article", "requestStatus": "handled" }, "searchResult": { "title": "Building RAG Pipelines with Web Browsers", "description": "Integrate web browsing into your RAG pipeline for real-time retrieval.", "url": "https://example.com/article", "resultType": "organic", "rank": 1 }, "metadata": { "title": "Building RAG Pipelines with Web Browsers", "description": "Add web browsing to RAG systems", "languageCode": "en", "url": "https://example.com/article" }, "markdown": "# Building RAG Pipelines with Web Browsers\n\n..." } ``` -------------------------------- ### Install Dependencies Source: https://github.com/apify/apify-docs/blob/master/GEMINI.md Installs project dependencies, including running patch-package via postinstall. ```bash pnpm install ``` -------------------------------- ### Get List of Keys from a Collection Source: https://github.com/apify/apify-docs/blob/master/sources/platform/actors/development/actor_definition/key_value_store_schema/index.md Use the API to list keys from a specific collection by using the `collection` query parameter. This example demonstrates fetching keys from the 'documents' collection. ```http GET https://api.apify.com/v2/key-value-stores/{storeId}/keys?collection=documents ``` -------------------------------- ### Install Dependencies Source: https://github.com/apify/apify-docs/blob/master/AGENTS.md Installs project dependencies, including running patch-package via postinstall. ```bash pnpm install # Install dependencies (runs patch-package via postinstall) ``` -------------------------------- ### Define Assistant Instructions Source: https://github.com/apify/apify-docs/blob/master/sources/platform/integrations/ai/openai/openai-assistants.md Set the instructions for the OpenAI Assistant, guiding its behavior, tone, and data sourcing. This example instructs the assistant to use the internet for answers and cite sources. ```python INSTRUCTIONS = """ You are a smart and helpful assistant. Maintain an expert, friendly, and informative tone in your responses. Your task is to answer questions based on information from the internet. Always call call_rag_web_browser function to retrieve the latest and most relevant online results. Never provide answers based solely on your own knowledge. For each answer, always include relevant sources whenever possible. """ ``` -------------------------------- ### Initialize npm Project Source: https://github.com/apify/apify-docs/blob/master/sources/academy/webscraping/scraping_basics_legacy/data_extraction/project_setup.md Run this command in your project directory to create a new npm project and generate a package.json file. ```shell npm init -y ``` -------------------------------- ### Python 2 Google SERP Proxy Request Source: https://github.com/apify/apify-docs/blob/master/sources/platform/proxy/google_serp_proxy.md An example for Python 2 users to access Google search results through the proxy. Ensure the 'six' library is installed and replace ``. ```python import six from six.moves.urllib import request, urlencode # Replace below with your password # found at https://console.apify.com/proxy password = '' proxy_url = ( 'http://groups-GOOGLE_SERP:%s@proxy.apify.com:8000' % (password) ) proxy_handler = request.ProxyHandler({ 'http': proxy_url, }) opener = request.build_opener(proxy_handler) query = parse.urlencode({ 'q': 'wikipedia' }) url = ( 'http://www.google.com/search?%s' % (query) ) print(opener.open(url).read()) ``` -------------------------------- ### Example Directory Structure Source: https://github.com/apify/apify-docs/blob/master/standards/file-organization.md A logical directory structure helps group related documentation. This example shows a typical structure for platform and educational content. ```text sources/ ├── platform/ # Platform documentation │ ├── actors/ # Actor-related content │ ├── storage/ # Storage documentation │ └── integrations/ # Integration guides └── academy/ # Educational content ├── tutorials/ # Step-by-step guides ├── webscraping/ # Web scraping courses ``` -------------------------------- ### Example File Name Source: https://github.com/apify/apify-docs/blob/master/standards/file-organization.md File names should use kebab-case and be descriptive of their content. ```text web-scraping-basics.md ``` -------------------------------- ### API Response Example for Default Dataset Output Source: https://github.com/apify/apify-docs/blob/master/sources/platform/actors/development/actor_definition/output_schema/index.md The `output` property in the `GET Run` API endpoint response will contain a URL pointing to the default dataset items when configured with an output schema. ```json "output": { "results": "https://api.apify.com/v2/datasets//items" } ```