aboutsummaryrefslogtreecommitdiffstats
path: root/db/mongo/scraper.js
blob: d28330f782e26b1c57d0c538f166af156f395661 (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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
"use strict";

const x = require("x-ray")();

async function getHTML(url) {
  const response = await fetch(url, {
    credentials: "include",
    headers: {
      "User-Agent":
        "Mozilla/5.0 (Windows NT 10.0; WOW64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.5666.197 Safari/537.36",
      Accept:
        "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
      "Accept-Language": "en-US,en;q=0.5",
      "Upgrade-Insecure-Requests": "1",
      "Sec-Fetch-Dest": "document",
      "Sec-Fetch-Mode": "navigate",
      "Sec-Fetch-Site": "none",
      "Sec-Fetch-User": "?1",
      "Sec-GPC": "1",
      "sec-ch-ua-platform": '"Windows"',
      "sec-ch-ua":
        '"Google Chrome";v="113", "Chromium";v="113", "Not=A?Brand";v="24"',
      "sec-ch-ua-mobile": "?0",
      Pragma: "no-cache",
      "Cache-Control": "no-cache",
    },
    method: "GET",
    mode: "cors",
  });

  if (response.ok) {
    console.log(response.body);
    const chunks = [];

    for await (const chunk of response.body) {
      chunks.push(Buffer.from(chunk));
    }

    return Buffer.concat(chunks).toString("utf-8");
  }
}

async function main() {
  const resultHTML = await getHTML("https://chapmanganato.com/manga-kd987838");

  x(
    resultHTML,
    "a.chapter-name.text-nowrap"
  )(function (err, lastChapter) {
    console.log(lastChapter);
    return lastChapter;
  });
}

main();