dms-scrape 0.1.3 → 0.2.0
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/README.md +1 -1
- package/lib/{processHTML.mjs → determineSource.mjs} +21 -14
- package/lib/fetchAndScrape.mjs +8 -8
- package/lib/justScrape.mjs +22 -14
- package/package.json +1 -1
- package/sources/handleUnsupported.mjs +6 -0
- package/test.mjs +3 -3
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/README.md
CHANGED
|
@@ -15,9 +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
|
-
|
|
19
|
-
function determineSource(link) {
|
|
20
|
-
if (link.includes("3c
|
|
18
|
+
import { handleUnsupported } from "../sources/handleUnsupported.mjs";
|
|
19
|
+
export function determineSource(link) {
|
|
20
|
+
// if (link.includes("3c") == undefined) {
|
|
21
|
+
// return handleUnsupported;
|
|
22
|
+
// } else
|
|
23
|
+
if (link.includes("3c.ltn")) {
|
|
21
24
|
return LTN3C; // Return the corresponding function
|
|
22
25
|
} else if (link.includes("ec.ltn")) {
|
|
23
26
|
return LTNEC;
|
|
@@ -36,23 +39,27 @@ function determineSource(link) {
|
|
|
36
39
|
} else if (link.includes("sogi")) {
|
|
37
40
|
return SOGI;
|
|
38
41
|
} else if (link.includes("techorange")) {
|
|
39
|
-
return TECHORANGE
|
|
42
|
+
return TECHORANGE;
|
|
40
43
|
} else if (link.includes("digitimes")) {
|
|
41
|
-
return DIGITIMES
|
|
44
|
+
return DIGITIMES;
|
|
42
45
|
} else if (link.includes("kocpc")) {
|
|
43
|
-
return KOCPC
|
|
46
|
+
return KOCPC;
|
|
44
47
|
} else if (link.includes("xfastest")) {
|
|
45
|
-
return XF
|
|
48
|
+
return XF;
|
|
46
49
|
} else if (link.includes("taisounds")) {
|
|
47
|
-
return TAISOUNDS
|
|
50
|
+
return TAISOUNDS;
|
|
48
51
|
} else if (link.includes("technews")) {
|
|
49
|
-
return TECHNEWS
|
|
52
|
+
return TECHNEWS;
|
|
50
53
|
} else if (link.includes("cna")) {
|
|
51
|
-
return CNA
|
|
54
|
+
return CNA;
|
|
55
|
+
} else {
|
|
56
|
+
return handleUnsupported(link);
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
59
|
|
|
55
|
-
export function processHTML(link, html) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
// export function processHTML(link, html) {
|
|
61
|
+
// const handlerFunction = determineSource(link);
|
|
62
|
+
// return handlerFunction == handleUnsupported
|
|
63
|
+
// ? handlerFunction(cheerio.load(html))
|
|
64
|
+
// : handlerFunction(link);
|
|
65
|
+
// }
|
package/lib/fetchAndScrape.mjs
CHANGED
|
@@ -2,17 +2,17 @@ import { justScrape } from "./justScrape.mjs";
|
|
|
2
2
|
export async function fetchAndScrape(link) {
|
|
3
3
|
var response;
|
|
4
4
|
try {
|
|
5
|
-
if (
|
|
5
|
+
// if (
|
|
6
6
|
// link.includes("digitimes") ||
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
) {
|
|
11
|
-
|
|
12
|
-
} else {
|
|
7
|
+
// link.includes("chinatimes") ||
|
|
8
|
+
// link.includes("ctee") ||
|
|
9
|
+
// link.includes("buzzorange")
|
|
10
|
+
// ) {
|
|
11
|
+
// return "Must use extension";
|
|
12
|
+
// } else {
|
|
13
13
|
response = await fetch(link);
|
|
14
14
|
return justScrape(link, await response.text());
|
|
15
|
-
}
|
|
15
|
+
// }
|
|
16
16
|
} catch (error) {
|
|
17
17
|
return error;
|
|
18
18
|
}
|
package/lib/justScrape.mjs
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
1
|
-
import { processHTML } from "./
|
|
1
|
+
// import { processHTML } from "./determineSource.mjs";
|
|
2
2
|
import { filterContent } from "./filterContent.mjs";
|
|
3
3
|
import { determineCategory } from "./determineCategory.mjs";
|
|
4
|
+
import { determineSource } from "./determineSource.mjs";
|
|
4
5
|
export function justScrape(link, html) {
|
|
5
6
|
try {
|
|
6
|
-
|
|
7
|
-
scrapedContent
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const handlerFunction = determineSource(link);
|
|
8
|
+
var scrapedContent =
|
|
9
|
+
typeof handlerFunction == "function"
|
|
10
|
+
? handlerFunction(cheerio.load(html))
|
|
11
|
+
: handlerFunction;
|
|
12
|
+
if (scrapedContent["error"] == undefined) {
|
|
13
|
+
scrapedContent["content"]
|
|
14
|
+
? (scrapedContent["content"] = filterContent(scrapedContent["content"]))
|
|
15
|
+
: "";
|
|
16
|
+
|
|
17
|
+
Array.isArray(scrapedContent["author"])
|
|
18
|
+
? (scrapedContent["author"] = scrapedContent["author"].toString())
|
|
19
|
+
: "";
|
|
20
|
+
Array.isArray(scrapedContent["date"])
|
|
21
|
+
? (scrapedContent["date"] = scrapedContent["date"].toString())
|
|
22
|
+
: "";
|
|
23
|
+
scrapedContent["category"] = determineCategory(scrapedContent["title"]);
|
|
24
|
+
scrapedContent["url"] = link;
|
|
25
|
+
scrapedContent["content"] = scrapedContent["content"].join("\n\n");
|
|
26
|
+
}
|
|
10
27
|
|
|
11
|
-
Array.isArray(scrapedContent["author"])
|
|
12
|
-
? (scrapedContent["author"] = scrapedContent["author"].toString())
|
|
13
|
-
: "";
|
|
14
|
-
Array.isArray(scrapedContent["date"])
|
|
15
|
-
? (scrapedContent["date"] = scrapedContent["date"].toString())
|
|
16
|
-
: "";
|
|
17
|
-
scrapedContent["category"] = determineCategory(scrapedContent["title"])
|
|
18
|
-
scrapedContent["url"] = link;
|
|
19
|
-
scrapedContent['content'] = scrapedContent['content'].join('\n\n')
|
|
20
28
|
return scrapedContent;
|
|
21
29
|
} catch (error) {
|
|
22
30
|
return error;
|
package/package.json
CHANGED
package/test.mjs
CHANGED
|
@@ -18,7 +18,7 @@ const testLinks = [
|
|
|
18
18
|
|
|
19
19
|
const buggedLinks = ["https://www.eprice.com.tw/mobile/talk/4523/5811558/1/"];
|
|
20
20
|
const testLink = [
|
|
21
|
-
"https://www.
|
|
21
|
+
"https://www.ctee.com.tw/news/20240805700832-431207",
|
|
22
22
|
];
|
|
23
23
|
async function getTestLinks() {
|
|
24
24
|
var response = [];
|
|
@@ -29,5 +29,5 @@ async function getTestLinks() {
|
|
|
29
29
|
// return await response.text();
|
|
30
30
|
return response;
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
console.log(await
|
|
32
|
+
|
|
33
|
+
console.log(await getTestLinks());
|