-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30041fb
commit 0c25cb0
Showing
11 changed files
with
2,279 additions
and
42 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,5 @@ logs/ | |
tmp/ | ||
|
||
*env.local | ||
|
||
javascript-sdk/node_modules |
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* eslint-env node */ | ||
module.exports = { | ||
root: true, | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", "prettier" | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": 12, | ||
"sourceType": "module" | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
printWidth: 100, | ||
trailingComma: 'all', | ||
singleQuote: true, | ||
importOrder: ['<THIRD_PARTY_MODULES>', '^@/types/(.*)$', '^@/lib/(.*)$', '^[./]'], | ||
importOrderSeparation: true, | ||
importOrderSortSpecifiers: true, | ||
importOrderCaseInsensitive: false, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Example script: collecting pricing data from e-commerce website using AgentQL | ||
|
||
This is an example of collecting pricing data from e-commerce website using AgentQL. | ||
|
||
## Run the script | ||
|
||
- [Install AgentQL SDK](https://docs.agentql.com/javascript-sdk/installation) | ||
- Save this python file locally as **first_steps.js** | ||
- Run the following command from the project's folder: | ||
|
||
```bash | ||
node first_steps.js | ||
``` | ||
|
||
## Play with the query | ||
|
||
Install the [AgentQL Debugger Chrome extension](https://docs.agentql.com/installation/chrome-extension-installation) to play with the AgentQL query. [Learn more about the AgentQL query language](https://docs.agentql.com/agentql-query/query-intro) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const { chromium } = require('playwright'); | ||
const { wrap, configure } = require('agentql'); | ||
|
||
const URL = 'https://scrapeme.live/shop'; | ||
|
||
// The AgentQL query to locate the search box element | ||
const SEARCH_BOX_QUERY = ` | ||
{ | ||
search_product_box | ||
} | ||
`; | ||
|
||
// The AgentQL query of the data to be extracted | ||
const PRODUCT_DATA_QUERY = ` | ||
{ | ||
price_currency | ||
products[] { | ||
name | ||
price | ||
} | ||
} | ||
`; | ||
|
||
// Other than the AgentQL query, you can also use natural language prompt to locate the element | ||
const NATURAL_LANGUAGE_PROMPT = 'Button to display Qwilfish page'; | ||
|
||
async function main() { | ||
// Configure the AgentQL API key | ||
configure({ apiKey: 'YOUR_API_KEY' }); | ||
|
||
const browser = await chromium.launch({ headless: false }); | ||
const context = await browser.newContext(); | ||
|
||
// Wrap the page to get access to the AgentQL's querying API | ||
const agentqlPage = wrap(await context.newPage()); | ||
|
||
await agentqlPage.goto(URL); | ||
|
||
const productData = await _extractProductData(agentqlPage, 'fish'); | ||
|
||
console.log(productData); | ||
|
||
await _addQwilfishToCart(agentqlPage); | ||
|
||
await browser.close(); | ||
} | ||
|
||
async function _extractProductData(page, searchKeyWord) { | ||
// Find DOM element using AgentQL API's queryElements() method | ||
const response = await page.queryElements(SEARCH_BOX_QUERY); | ||
|
||
// Interact with the element using Playwright API | ||
await response.search_product_box.type(searchKeyWord, { delay: 200 }); | ||
await page.keyboard.press('Enter'); | ||
|
||
// Extract data using AgentQL API's queryData() method | ||
const data = await page.queryData(PRODUCT_DATA_QUERY); | ||
|
||
return data; | ||
} | ||
|
||
async function _addQwilfishToCart(page) { | ||
// Find DOM element using AgentQL API's getByPrompt() method | ||
const qwilfishPageBtn = await page.getByPrompt(NATURAL_LANGUAGE_PROMPT); | ||
|
||
// Interact with the element using Playwright API | ||
if (qwilfishPageBtn) { | ||
await qwilfishPageBtn.click(); | ||
} | ||
|
||
// Wait for 10 seconds to see the browser action | ||
await page.waitForTimeout(10000); | ||
} | ||
|
||
main(); |
Oops, something went wrong.