dms-scrape 0.2.0 → 0.3.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/index.mjs +4 -5
- package/lib/{determineSource.mjs → processHTML.mjs} +32 -14
- package/package.json +3 -2
- 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/lib/fetchAndScrape.mjs +0 -19
- package/lib/justScrape.mjs +0 -32
- package/sources/handleUnsupported.mjs +0 -6
package/lib/fetchAndScrape.mjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { justScrape } from "./justScrape.mjs";
|
|
2
|
-
export async function fetchAndScrape(link) {
|
|
3
|
-
var response;
|
|
4
|
-
try {
|
|
5
|
-
// if (
|
|
6
|
-
// link.includes("digitimes") ||
|
|
7
|
-
// link.includes("chinatimes") ||
|
|
8
|
-
// link.includes("ctee") ||
|
|
9
|
-
// link.includes("buzzorange")
|
|
10
|
-
// ) {
|
|
11
|
-
// return "Must use extension";
|
|
12
|
-
// } else {
|
|
13
|
-
response = await fetch(link);
|
|
14
|
-
return justScrape(link, await response.text());
|
|
15
|
-
// }
|
|
16
|
-
} catch (error) {
|
|
17
|
-
return error;
|
|
18
|
-
}
|
|
19
|
-
}
|
package/lib/justScrape.mjs
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// import { processHTML } from "./determineSource.mjs";
|
|
2
|
-
import { filterContent } from "./filterContent.mjs";
|
|
3
|
-
import { determineCategory } from "./determineCategory.mjs";
|
|
4
|
-
import { determineSource } from "./determineSource.mjs";
|
|
5
|
-
export function justScrape(link, html) {
|
|
6
|
-
try {
|
|
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
|
-
}
|
|
27
|
-
|
|
28
|
-
return scrapedContent;
|
|
29
|
-
} catch (error) {
|
|
30
|
-
return error;
|
|
31
|
-
}
|
|
32
|
-
}
|