Created
November 9, 2024 23:37
-
-
Save rachelnabors/0894de2b18bd4354407a7ec13bc3d138 to your computer and use it in GitHub Desktop.
Implementation of ZenRows with AgentQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Learn more about agentQL at AgentQL.com | |
const { wrap, configure } = require('agentql'); | |
const { chromium } = require('playwright'); | |
# Learn more about Zenrows browser API at https://docs.zenrows.com/scraping-browser/get-started/playwright | |
const connectionURL = 'wss://browser.zenrows.com?apikey=' + process.env.ZENROWS_API_KEY; | |
// Set the URL to the desired website | |
const URL = 'https://www.etsy.com/uk/search?q=gift&anchor_listing_id=1807561558&mosv=ssos&moci=1299343889674&mosi=1299363012586&is_merch_library=true&max=30'; | |
async function main() { | |
// Configure the AgentQL API key | |
configure({ | |
apiKey: process.env.AGENTQL_API_KEY, // This is the default and can be omitted. | |
}); | |
// point the browser to the ZenRows service | |
const browser = await chromium.connectOverCDP(connectionURL); | |
// Wrap the page to get access to the AgentQL's querying API | |
const page = await wrap(await browser.newPage()); | |
// Navigate to the URL | |
await page.goto(URL); | |
const query = `{ | |
products[] { | |
name | |
price | |
} | |
}`; | |
// Get the products from the page | |
const products = await page.queryData(query); | |
console.log(products); | |
// Used only for demo purposes. It allows you to see the effect of the script. | |
await page.waitForTimeout(10000); | |
await browser.close(); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment