diff options
| author | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-10-19 20:43:04 +0200 |
|---|---|---|
| committer | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-10-19 20:43:04 +0200 |
| commit | 2bfae5b426bf4a0b99d3979ed12d63cb50c39b17 (patch) | |
| tree | d1a3c622e9b13e66e16b3e7b96068c67933ad950 /examples/hackernews.js | |
| parent | 135eff4287c06aff9604a4d0b9ddea1740f6c836 (diff) | |
Add examples
Diffstat (limited to 'examples/hackernews.js')
| -rw-r--r-- | examples/hackernews.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/hackernews.js b/examples/hackernews.js new file mode 100644 index 0000000..71dc52f --- /dev/null +++ b/examples/hackernews.js @@ -0,0 +1,25 @@ +export const config = { + url: "https://news.ycombinator.com/", + depth: 9, + cache: "file", + follow: ["a.morelink[href]"], +}; + +export default function({ doc, absoluteURL }) { + const posts = doc.find(".athing"); + + return { + posts: posts.map((post) => { + const link = post.find(".titleline > a"); + const meta = post.next(); + + return { + url: absoluteURL(link.attr("href")), + user: meta.find(".hnuser").text(), + title: link.text(), + points: meta.find(".score").text().replace(" points", ""), + created: meta.find(".age").attr("title"), + }; + }), + }; +} |