@wargas/crawler 0.0.1 → 0.0.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.
- package/bun.lock +31 -0
- package/dist/index.js +19745 -9520
- package/index.test.ts +12 -0
- package/index.ts +18 -1
- package/package.json +2 -1
- package/tsconfig.json +1 -1
package/index.test.ts
ADDED
package/index.ts
CHANGED
|
@@ -2,10 +2,13 @@ import type { Got } from "got";
|
|
|
2
2
|
import got from "got";
|
|
3
3
|
import { CookieJar } from "tough-cookie";
|
|
4
4
|
import FileCookieStore from "tough-cookie-file-store";
|
|
5
|
+
import { parseHTML } from "linkedom"
|
|
5
6
|
|
|
6
7
|
export class Crawler {
|
|
7
8
|
client!: Got
|
|
8
9
|
cookieJar!: CookieJar
|
|
10
|
+
html = ``
|
|
11
|
+
document = parseHTML(``).document
|
|
9
12
|
|
|
10
13
|
static factory() {
|
|
11
14
|
const instance = new Crawler()
|
|
@@ -13,7 +16,21 @@ export class Crawler {
|
|
|
13
16
|
instance.cookieJar = new CookieJar(new FileCookieStore(`cookies.json`))
|
|
14
17
|
|
|
15
18
|
instance.client = got.extend({
|
|
16
|
-
|
|
19
|
+
hooks: {
|
|
20
|
+
afterResponse: [
|
|
21
|
+
res => {
|
|
22
|
+
if(typeof res.body == `string`) {
|
|
23
|
+
instance.html = res.body
|
|
24
|
+
instance.document = parseHTML(res.body).document
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return res
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
// followRedirect:false,
|
|
32
|
+
// cookieJar: instance.cookieJar,
|
|
33
|
+
|
|
17
34
|
})
|
|
18
35
|
|
|
19
36
|
return instance;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wargas/crawler",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"module": "index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"got": "^15.0.5",
|
|
19
|
+
"linkedom": "^0.18.12",
|
|
19
20
|
"tough-cookie": "^6.0.1",
|
|
20
21
|
"tough-cookie-file-store": "^3.3.0"
|
|
21
22
|
}
|