1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-09-16 09:06:36 +02:00

Updated example with Google Search

This commit is contained in:
Tim Voronov
2018-10-08 23:28:15 -04:00
parent 3829dffb91
commit 65a7f2a2df
2 changed files with 21 additions and 33 deletions

View File

@@ -17,25 +17,19 @@ The final for loop filters out empty elements that might be because of inaccurat
```aql
LET google = DOCUMENT("https://www.google.com/", true)
INPUT(google, 'input[name="q"]', "ferret")
INPUT(google, 'input[name="q"]', "ferret", 25)
CLICK(google, 'input[name="btnK"]')
WAIT_NAVIGATION(google)
LET result = (
FOR result IN ELEMENTS(google, '.g')
RETURN {
title: ELEMENT(result, 'h3 > a'),
description: ELEMENT(result, '.st'),
url: ELEMENT(result, 'cite')
}
)
RETURN (
FOR page IN result
FILTER page.title != NONE
RETURN page
)
FOR result IN ELEMENTS(google, '.g')
// filter out extra elements like videos and 'People also ask'
FILTER TRIM(result.attributes.class) == 'g'
RETURN {
title: INNER_TEXT(result, 'h3'),
description: INNER_TEXT(result, '.st'),
url: INNER_TEXT(result, 'cite')
}
```
More examples you can find [here](./examples)

View File

@@ -1,21 +1,15 @@
LET g = DOCUMENT("https://www.google.com/", true)
LET google = DOCUMENT("https://www.google.com/", true)
INPUT(g, 'input[name="q"]', "ferret", 25)
CLICK(g, 'input[name="btnK"]')
INPUT(google, 'input[name="q"]', "ferret", 25)
CLICK(google, 'input[name="btnK"]')
WAIT_NAVIGATION(g)
WAIT_NAVIGATION(google)
LET result = (
FOR result IN ELEMENTS(g, '.g')
RETURN {
title: ELEMENT(result, 'h3 > a'),
description: ELEMENT(result, '.st'),
url: ELEMENT(result, 'cite')
}
)
RETURN (
FOR i IN result
FILTER i.title != NONE
RETURN i
)
FOR result IN ELEMENTS(google, '.g')
// filter out extra elements like videos and 'People also ask'
FILTER TRIM(result.attributes.class) == 'g'
RETURN {
title: INNER_TEXT(result, 'h3'),
description: INNER_TEXT(result, '.st'),
url: INNER_TEXT(result, 'cite')
}