diff --git a/content/docs/getting-started.md b/content/docs/getting-started.md index bc7cf7a..fb2eba1 100644 --- a/content/docs/getting-started.md +++ b/content/docs/getting-started.md @@ -9,33 +9,38 @@ draft: false If you want to play with FQL and check its syntax, you can run CLI with the following commands to run Ferret CLI in REPL mode: ```bash -$ ferret +$ ferret exec ``` ```bash Welcome to Ferret REPL Please use `exit` or `Ctrl-D` to exit this program. ->% ->LET doc = DOCUMENT('https://news.ycombinator.com/') ->FOR post IN ELEMENTS(doc, '.storylink') ->RETURN post.attributes.href ->% +> % +> LET doc = DOCUMENT("https://news.ycombinator.com/") +> FOR post IN ELEMENTS(doc, '.titleline > a') +> RETURN { +> title: TRIM(INNER_TEXT(post)), +> link: ATTR_GET(post, 'href') +> } +> % ``` **NOTE**: symbol % is used to start and end multi-line queries. You also can use the heredoc format. +Use `exit` to quit the REPL. + If you want to execute a query stored in a file, just pass a file name: ```bash -$ ferret ./docs/examples/static-page.fql +$ ferret exec ./docs/examples/static-page.fql ``` ```bash -$ cat ./docs/examples/static-page.fql | ferret +$ cat ./docs/examples/static-page.fql | ferret exec ``` ```bash -$ ferret < ./docs/examples/static-page.fql +$ ferret exec < ./docs/examples/static-page.fql ``` ### Browser mode @@ -60,15 +65,20 @@ $ docker run -d -p 9222:9222 montferret/chromium Second, you need to pass the address to Ferret CLI. ```bash -$ ferret --cdp http://127.0.0.1:9222 +$ ferret exec -d "http://127.0.0.1:9222" ``` -**NOTE**: By default, Ferret will try to use this local address as a default one, so it makes sense to explicitly pass the parameter only in case of either different port number or remote address. +**NOTE**: By default, Ferret will try to use this local address as a default one, so it makes sense to explicitly pass the parameter only in case of either different port number or remote address. So in this case, specifying the address makes no difference as long as the `driver` parameter is set with `cdp` in the query. + +```bash +> LET doc = DOCUMENT('https://soundcloud.com/charts/top', { driver: "cdp" }) +``` Alternatively, you can tell CLI to launch Chrome for you. ```bash -$ ferret --cdp-launch +$ ferret exec --browser-headless +$ ferret exec --browser-open # browser with head ``` Once Ferret knows how to communicate with Chrome, you can use ``DOCUMENT(url, opts)`` function with true boolean value for dynamic pages: @@ -79,8 +89,7 @@ Please use `exit` or `Ctrl-D` to exit this program. >% >LET doc = DOCUMENT('https://soundcloud.com/charts/top', { driver: "cdp" }) >WAIT_ELEMENT(doc, '.chartTrack__details', 5000) ->LET tracks = ELEMENTS(doc, '.chartTrack__details') ->FOR track IN tracks +>FOR track IN ELEMENTS(doc, '.chartTrack__details') > LET username = ELEMENT(track, '.chartTrack__username') > LET title = ELEMENT(track, '.chartTrack__title') > RETURN { @@ -88,4 +97,4 @@ Please use `exit` or `Ctrl-D` to exit this program. > track: title.innerText > } >% -``` \ No newline at end of file +```