summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorRafael Bodill <rafi@users.noreply.github.com>2024-11-24 13:59:48 +0200
committerGitHub <noreply@github.com>2024-11-24 12:59:48 +0100
commitd2aec146ac5a2aef4a87813be47e5e1dc7404c51 (patch)
tree7407bd1f69e999f1409d82c1e9d3fce80a353845 /README.md
parent54a8ea0bc36d6bb401b942bb2644c316c55c4ff9 (diff)
Add tag name and more traversal methods (#73)
Diffstat (limited to 'README.md')
-rw-r--r--README.md18
1 files changed, 18 insertions, 0 deletions
diff --git a/README.md b/README.md
index d10ce44..233e2ca 100644
--- a/README.md
+++ b/README.md
@@ -273,6 +273,7 @@ export default function ({ doc, url, absoluteURL }) {
const el = doc.find(".element")
el.text() // "Hey"
el.html() // `<div class="element">Hey</div>`
+el.name() // div
el.attr("foo") // "bar"
el.hasAttr("foo") // true
el.hasClass("element") // true
@@ -296,6 +297,23 @@ items.get(1).parent() // <ul>...</ul>
items.get(1).siblings() // [<li class="a">Item 1</li>, <li>Item 2</li>, <li>Item 3</li>]
items.map(item => item.text()) // ["Item 1", "Item 2", "Item 3"]
items.filter(item => item.hasClass("a")) // [<li class="a">Item 1</li>]
+
+// <div>
+// <h2 id="aleph">Aleph</h2>
+// <p>Aleph</p>
+// <h2 id="beta">Beta</h2>
+// <p>Beta</p>
+// <h2 id="gamma">Gamma</h2>
+// <p>Gamma</p>
+// </div>
+const header = doc.find("div h2")
+
+header.get(1).prev() // <p>Aleph</p>
+header.get(1).prevAll() // [<p>Aleph</p>, <h2 id="aleph">Aleph</h2>]
+header.get(1).prevUntil('div,h1,h2,h3') // <h2 id="aleph">Aleph</h2>
+header.get(1).next() // <p>Beta</p>
+header.get(1).nextAll() // [<p>Beta</p>, <h2 id="gamma">Gamma</h2>, <p>Gamma</p>]
+header.get(1).nextUntil('div,h1,h2,h3') // <p>Beta</p>
```
## Flyscrape API