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 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
@@ -19,7 +19,6 @@
19
19
  ### T3 電視台
20
20
  - [x] 三立
21
21
  - [ ] 華視
22
- - [ ] 三立新聞台
23
22
  - [ ] 東森新聞
24
23
  - [ ] 民視新聞網
25
24
  - [ ] TVBS
@@ -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 'cheerio'
3
+ import * as cheerio from "cheerio";
4
4
  function checkLink(link) {
5
- const linksNeedText = ["digitimes", "ctee", "chinatimes", "techorange"];
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.includes(l)) {
8
- return true;
13
+ if (link.startsWith(l)) {
14
+ resp = true;
15
+ break;
9
16
  } else {
10
- return false;
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.includes("高通"):
3
+ case title?.includes("高通"):
4
4
  return "qualcomm";
5
5
 
6
- case title.includes("聯發科"):
6
+ case title?.includes("聯發科"):
7
7
  return "mediatek";
8
8
 
9
- case title.includes("5G"):
9
+ case title?.includes("5G"):
10
10
  return "commu";
11
11
 
12
- case title.includes("OPPO") || title.includes("PC"):
12
+ case title?.includes("OPPO") || title?.includes("PC"):
13
13
  return "phone";
14
14
 
15
15
  default:
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "dms-scrape",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "main": "index.mjs",
5
5
  "type": "module",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
7
+ "test": "node test.mjs"
8
8
  },
9
9
  "author": "",
10
10
  "license": "ISC",
@@ -20,9 +20,14 @@
20
20
  export function CHINATIMES($) {
21
21
  const data = $.extract({
22
22
  title: "h1.article-title",
23
- date: [{ selector: "span.date", value: (el) => $(el).text().replace(/\//g, "-") }],
24
- source: "div.source",
25
- author: "div.author",
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",