dms-scrape 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -2
- package/index.mjs +4 -5
- package/lib/{determineSource.mjs → processHTML.mjs} +32 -14
- package/package.json +3 -2
- package/sources/T1/UDNMoney.mjs +3 -3
- package/sources/T1/digitimes.html +2598 -0
- package/sources/T1/digitimes2.html +2567 -0
- package/sources/T1/digitimes3.html +2598 -0
- package/sources/T1/digitimes4.html +2614 -0
- package/test.mjs +1 -1
- package/lib/fetchAndScrape.mjs +0 -19
- package/lib/justScrape.mjs +0 -33
- package/sources/handleUnsupported.mjs +0 -6
package/.gitattributes
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
# Auto detect text files and perform LF normalization
|
|
2
|
-
* text=auto
|
|
1
|
+
# Auto detect text files and perform LF normalization
|
|
2
|
+
* text=auto
|
package/index.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { justScrape } from "./lib/justScrape.mjs";
|
|
1
|
+
import { processHTML } from "./lib/processHTML.mjs";
|
|
3
2
|
export async function dmsScrape(type, link, html) {
|
|
4
3
|
return type == "link"
|
|
5
|
-
? await
|
|
4
|
+
? processHTML(link, await (await fetch(link)).text())
|
|
6
5
|
: type == "html"
|
|
7
|
-
?
|
|
8
|
-
: "Must specify type";
|
|
6
|
+
? processHTML(link, html)
|
|
7
|
+
: { error: "Must specify type", url: link };
|
|
9
8
|
}
|
|
@@ -15,13 +15,12 @@ import { XF } from "../sources/T5/XF.mjs";
|
|
|
15
15
|
import { TAISOUNDS } from "../sources/T4/TAISOUNDS.mjs";
|
|
16
16
|
import { TECHNEWS } from "../sources/T5/TECHNEWS.mjs";
|
|
17
17
|
import { CNA } from "../sources/T4/CNA.mjs";
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return LTN3C; // Return the corresponding function
|
|
18
|
+
import { v4 as uuid } from "uuid";
|
|
19
|
+
import { filterContent } from "./filterContent.mjs";
|
|
20
|
+
import { determineCategory } from "./determineCategory.mjs";
|
|
21
|
+
function determineSource(link) {
|
|
22
|
+
if (link.includes("3c.ltn")) {
|
|
23
|
+
return LTN3C;
|
|
25
24
|
} else if (link.includes("ec.ltn")) {
|
|
26
25
|
return LTNEC;
|
|
27
26
|
} else if (link.includes("money.udn")) {
|
|
@@ -53,13 +52,32 @@ export function determineSource(link) {
|
|
|
53
52
|
} else if (link.includes("cna")) {
|
|
54
53
|
return CNA;
|
|
55
54
|
} else {
|
|
56
|
-
return
|
|
55
|
+
return "unsupported";
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
export function processHTML(link, html) {
|
|
60
|
+
const handlerFunction = determineSource(link);
|
|
61
|
+
let scrapedContent;
|
|
62
|
+
handlerFunction != "unsupported"
|
|
63
|
+
? ((scrapedContent = handlerFunction(cheerio.load(html))),
|
|
64
|
+
(scrapedContent["content"] = scrapedContent["content"]
|
|
65
|
+
? filterContent(scrapedContent["content"]).join("\n\n")
|
|
66
|
+
: scrapedContent["content"]),
|
|
67
|
+
(scrapedContent["author"] = Array.isArray(scrapedContent["author"])
|
|
68
|
+
? scrapedContent["author"].toString()
|
|
69
|
+
: scrapedContent["author"]),
|
|
70
|
+
(scrapedContent["date"] = Array.isArray(scrapedContent["date"])
|
|
71
|
+
? scrapedContent["date"].toString()
|
|
72
|
+
: scrapedContent["date"]),
|
|
73
|
+
(scrapedContent["category"] = determineCategory(scrapedContent["title"])),
|
|
74
|
+
(scrapedContent["url"] = link),
|
|
75
|
+
(scrapedContent["content"] = scrapedContent["content"]))
|
|
76
|
+
: (scrapedContent = {
|
|
77
|
+
error: handlerFunction,
|
|
78
|
+
url: link,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
scrapedContent["id"] = uuid();
|
|
82
|
+
return scrapedContent
|
|
83
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dms-scrape",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"main": "index.mjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"esbuild": "^0.23.1"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"cheerio": "^1.0.0"
|
|
16
|
+
"cheerio": "^1.0.0",
|
|
17
|
+
"uuid": "^10.0.0"
|
|
17
18
|
}
|
|
18
19
|
}
|
package/sources/T1/UDNMoney.mjs
CHANGED
|
@@ -23,16 +23,16 @@ export function UDNMoney($) {
|
|
|
23
23
|
{
|
|
24
24
|
selector: "section.article-body__editor p",
|
|
25
25
|
value: (el, key) => {
|
|
26
|
-
const sampleKey = this.findIndex(item => item.includes("延伸閱讀"))
|
|
26
|
+
// const sampleKey = this.findIndex(item => item.includes("延伸閱讀"))
|
|
27
27
|
if (!$(el).text().trim() == "") {
|
|
28
28
|
const sample = $(el)
|
|
29
29
|
.text()
|
|
30
30
|
.replace(/\$\(.*/s, "")
|
|
31
31
|
.trim();
|
|
32
32
|
|
|
33
|
-
if (key < sampleKey) {
|
|
33
|
+
// if (key < sampleKey) {
|
|
34
34
|
return sample;
|
|
35
|
-
}
|
|
35
|
+
// }
|
|
36
36
|
|
|
37
37
|
}
|
|
38
38
|
},
|