dms-scrape 0.4.0 → 0.4.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/README.md +0 -1
- package/extractfrombrowser.js +1 -1
- package/index.mjs +13 -5
- package/lib/determineCategory.mjs +4 -4
- package/package.json +2 -2
- package/sources/T2/CHINATIMES.mjs +8 -3
- package/test/tested/digitest.js +1664 -0
- package/test.mjs +28 -2
- package/test/tested/digitest.html +0 -1789
- package/test/tested/digitimes2.js +0 -2218
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
package/extractfrombrowser.js
CHANGED
|
@@ -5,7 +5,7 @@ var tempDiv = document.createElement('div');
|
|
|
5
5
|
tempDiv.innerHTML = fullHTML;
|
|
6
6
|
|
|
7
7
|
// Remove all <script> and <style> tags
|
|
8
|
-
var scriptsAndStyles = tempDiv.querySelectorAll('script, style, link');
|
|
8
|
+
var scriptsAndStyles = tempDiv.querySelectorAll('script, style, link, g, noscript, svg, img, symbol, figure, figcaption, ins');
|
|
9
9
|
scriptsAndStyles.forEach(tag => tag.remove());
|
|
10
10
|
|
|
11
11
|
// Print the HTML without the <script> and <style> tags
|
package/index.mjs
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import { processHTML } from "./lib/processHTML.mjs";
|
|
2
2
|
import { v4 as uuid } from "uuid";
|
|
3
|
-
import * as cheerio from
|
|
3
|
+
import * as cheerio from "cheerio";
|
|
4
4
|
function checkLink(link) {
|
|
5
|
-
|
|
5
|
+
let resp;
|
|
6
|
+
const linksNeedText = [
|
|
7
|
+
"https://www.digitimes",
|
|
8
|
+
"https://www.ctee",
|
|
9
|
+
"https://www.chinatimes",
|
|
10
|
+
"https://buzzorange.com/techorange",
|
|
11
|
+
];
|
|
6
12
|
for (const l of linksNeedText) {
|
|
7
|
-
if (link.
|
|
8
|
-
|
|
13
|
+
if (link.startsWith(l)) {
|
|
14
|
+
resp = true;
|
|
15
|
+
break;
|
|
9
16
|
} else {
|
|
10
|
-
|
|
17
|
+
resp = false;
|
|
11
18
|
}
|
|
12
19
|
}
|
|
20
|
+
return resp;
|
|
13
21
|
}
|
|
14
22
|
export async function dmsScrape(type, link, html) {
|
|
15
23
|
var data;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export function determineCategory(title) {
|
|
2
2
|
switch (true) {
|
|
3
|
-
case title
|
|
3
|
+
case title?.includes("高通"):
|
|
4
4
|
return "qualcomm";
|
|
5
5
|
|
|
6
|
-
case title
|
|
6
|
+
case title?.includes("聯發科"):
|
|
7
7
|
return "mediatek";
|
|
8
8
|
|
|
9
|
-
case title
|
|
9
|
+
case title?.includes("5G"):
|
|
10
10
|
return "commu";
|
|
11
11
|
|
|
12
|
-
case title
|
|
12
|
+
case title?.includes("OPPO") || title?.includes("PC"):
|
|
13
13
|
return "phone";
|
|
14
14
|
|
|
15
15
|
default:
|
package/package.json
CHANGED
|
@@ -20,9 +20,14 @@
|
|
|
20
20
|
export function CHINATIMES($) {
|
|
21
21
|
const data = $.extract({
|
|
22
22
|
title: "h1.article-title",
|
|
23
|
-
date: [
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
date: [
|
|
24
|
+
{
|
|
25
|
+
selector: "span.date:first",
|
|
26
|
+
value: (el) => $(el).text().replace(/\//g, "-"),
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
source: [{ selector: "div.source", value: (el) => $(el).text().trim() }],
|
|
30
|
+
author: [{ selector: "div.author", value: (el) => $(el).text().trim() }],
|
|
26
31
|
content: [
|
|
27
32
|
{
|
|
28
33
|
selector: "div.article-body p",
|