From b1e2c8fd5cb5dfa46bc440a12eafaf56cd844b1c Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Mon, 24 Nov 2025 20:54:57 +0100 Subject: Docs --- content/docs/api-reference.md | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 content/docs/api-reference.md (limited to 'content/docs/api-reference.md') diff --git a/content/docs/api-reference.md b/content/docs/api-reference.md new file mode 100644 index 0000000..99ac2f9 --- /dev/null +++ b/content/docs/api-reference.md @@ -0,0 +1,61 @@ +--- +title: 'API Reference' +weight: 4 +next: '/docs/configuration' +--- + +## Query API + +```javascript{filename="Reference"} +//
Hey
+const el = doc.find(".element") +el.text() // "Hey" +el.html() // `
Hey
` +el.attr("foo") // "bar" +el.hasAttr("foo") // true +el.hasClass("element") // true + +// +const list = doc.find("ul") +list.children() // [
  • Item 1
  • ,
  • Item 2
  • ,
  • Item 3
  • ] + +const items = list.find("li") +items.length() // 3 +items.first() //
  • Item 1
  • +items.last() //
  • Item 3
  • +items.get(1) //
  • Item 2
  • +items.get(1).prev() //
  • Item 1
  • +items.get(1).next() //
  • Item 3
  • +items.get(1).parent() // +items.get(1).siblings() // [
  • Item 1
  • ,
  • Item 2
  • ,
  • Item 3
  • ] +items.map(item => item.text()) // ["Item 1", "Item 2", "Item 3"] +items.filter(item => item.hasClass("a")) // [
  • Item 1
  • ] +``` + +## Document Parsing + +```javascript{filename="Reference"} +import { parse } from "flyscrape"; + +const doc = parse(`
    bar
    `); +const text = doc.find(".foo").text(); +``` + +## File Downloads + +```javascript{filename="Reference"} +import { download } from "flyscrape/http"; + +download("http://example.com/image.jpg") // downloads as "image.jpg" +download("http://example.com/image.jpg", "other.jpg") // downloads as "other.jpg" +download("http://example.com/image.jpg", "dir/") // downloads as "dir/image.jpg" + +// If the server offers a filename via the Content-Disposition header and no +// destination filename is provided, Flyscrape will honor the suggested filename. +// E.g. `Content-Disposition: attachment; filename="archive.zip"` +download("http://example.com/generate_archive.php", "dir/") // downloads as "dir/archive.zip" +``` -- cgit v1.2.3