dms-scrape 0.1.1 → 0.1.2

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.
@@ -0,0 +1,18 @@
1
+ export function determineCategory(title) {
2
+ switch (true) {
3
+ case title.includes("高通"):
4
+ return "Qualcomm相關新聞";
5
+
6
+ case title.includes("聯發科"):
7
+ return "MediaTek相關新聞";
8
+
9
+ case title.includes("5G"):
10
+ return "無線通訊市場";
11
+
12
+ case title.includes("OPPO") || title.includes("PC"):
13
+ return "智慧型手機/消費性電子產品";
14
+
15
+ default:
16
+ return "其他業界重要訊息";
17
+ }
18
+ }
@@ -1,5 +1,6 @@
1
1
  import { processHTML } from "./processHTML.mjs";
2
2
  import { filterContent } from "./filterContent.mjs";
3
+ import { determineCategory } from "./determineCategory.mjs";
3
4
  export function justScrape(link, html) {
4
5
  try {
5
6
  var scrapedContent = processHTML(link, html);
@@ -13,6 +14,7 @@ export function justScrape(link, html) {
13
14
  Array.isArray(scrapedContent["date"])
14
15
  ? (scrapedContent["date"] = scrapedContent["date"].toString())
15
16
  : "";
17
+ scrapedContent["category"] = determineCategory(scrapedContent["title"])
16
18
  scrapedContent["url"] = link;
17
19
  return scrapedContent;
18
20
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dms-scrape",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "main": "index.mjs",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1,6 +1,6 @@
1
1
  export function UDNMoney($) {
2
2
  const data = $.extract({
3
- headline: "h1#story_art_title",
3
+ title: "h1#story_art_title",
4
4
  date: [
5
5
  {
6
6
  selector: "time.article-body__time",
@@ -1,6 +1,6 @@
1
1
  export function LTN3C($) {
2
2
  const data = $.extract({
3
- headline: "div.whitecon.borderline.boxTitle.boxText h1",
3
+ title: "div.whitecon.borderline.boxTitle.boxText h1",
4
4
  date: [
5
5
  {
6
6
  selector: "span.time",
@@ -1,6 +1,6 @@
1
1
  export function LTNEC($) {
2
2
  const data = $.extract({
3
- headline: "div.whitecon.boxTitle.boxText h1",
3
+ title: "div.whitecon.boxTitle.boxText h1",
4
4
  date: [
5
5
  {
6
6
  selector: "span.time:nth-of-type(1)",
@@ -1,6 +1,6 @@
1
1
  export function UDN($) {
2
2
  const data = $.extract({
3
- headline: "h1.article-content__title",
3
+ title: "h1.article-content__title",
4
4
  date: [
5
5
  {
6
6
  selector: "time.article-content__time",
@@ -1,6 +1,6 @@
1
1
  export function ETDAY($) {
2
2
  const data = $.extract({
3
- headline: "h1.title",
3
+ title: "h1.title",
4
4
  date: [
5
5
  {
6
6
  selector: "time.date",
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.cna.com.tw/news/afe/202407160341.aspx?topic=3407",
21
+ "https://www.ettoday.net/news/20240905/2810968.htm",
22
22
  ];
23
23
  async function getTestLinks() {
24
24
  var response = [];