Skip to content

Commit

Permalink
Update Getting Started (#34)
Browse files Browse the repository at this point in the history
* Update getting-started.md

The commands depicted are not correct anymore + some clarifications.

* Added document driver example
  • Loading branch information
oornaque authored Nov 15, 2023
1 parent fd64062 commit a1d9545
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions content/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -79,13 +89,12 @@ 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 {
> artist: username.innerText,
> track: title.innerText
> }
>%
```
```

0 comments on commit a1d9545

Please sign in to comment.