summaryrefslogtreecommitdiff
path: root/examples/hackernews_with_comments.js
blob: 8d9cfb5968899f2dc1421ada9e3b32805839ff65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
export const config = {
  url: "https://news.ycombinator.com/",
};

export default function({ doc, scrape }) {
  const post = doc.find(".athing.submission").first();
  const title = post.find(".titleline > a").text();
  const commentsLink = post.next().find("a").last().attr("href");

  const comments = scrape(commentsLink, function({ doc }) {
    return doc.find(".comtr").map(comment => {
      return {
        author: comment.find(".hnuser").text(),
        text: comment.find(".commtext").text(),
      };
    });
  });

  return {
    title,
    comments,
  };
}