Summarize a webpage
Overview
This recipe demonstrates how to use Airtop to automate the summarization of a webpage. By leveraging Airtop’s cloud browser capabilities, we can extract a concise summary from any webpage using a simple API.
The instructions below will walk through creating a script that connects to Airtop, opens a webpage in a cloud browser session, and retrieves a summary of its content. The full source code is available on GitHub for your reference.
Prerequisites
To get started, ensure you have:
- Node.js installed on your system.
- An Airtop API key. You can get one for free.
Getting Started
-
Clone the repository
Start by cloning the source code from GitHub:
-
Install dependencies
Run the following command to install the necessary dependencies, including the Airtop SDK:
-
Configure your environment
You will need to provide your Airtop API key in a
.env
file. First, copy the provided example.env
file:Now edit the
.env
file to add your Airtop API key:
Script Walkthrough
The script in index.ts
performs the following steps:
-
Initialize the Airtop Client
First, we initialize the
AirtopClient
using your provided API key. This client will be used to create browser sessions and interact with the page content. -
Create a Browser Session
Creating a browser session will allow us to connect to and control a cloud-based browser.
-
Connect to the Browser
The script opens a new page and navigates to the target URL. In this example we use a a Wikipedia page, however you can replace this with the URL of your choice.
-
Summarize the Content
Leverage Airtop to summarize the webpage’s content using natural language. We utilize the
pageQuery
API to specify how the summary should be structured.Here we instruct Airtop to summarize the content of the page in 1 paragraph, however you can customize this prompt to suit your needs (i.e. asking it to provide bullet points).
-
Clean Up
Finally, the script closes the window and terminates the session.
Running the Script
To run the script, execute the following command in your terminal:
Summary
Airtop makes extracting key information from web pages as simple as writing a few lines of code. By combining the power of cloud browser automation with AI summarization, you can efficiently gather and understand content from any website on the internet.