diff options
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"), + }; + }), + }; +} |