@wargas/crawler 0.0.4 → 0.0.5
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/README.md +100 -6
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -1,15 +1,109 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Crawler
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Classe utilitária para realizar requisições HTTP com:
|
|
4
|
+
|
|
5
|
+
* Persistência automática de cookies
|
|
6
|
+
* Parsing automático de HTML
|
|
7
|
+
* Manipulação do DOM usando `linkedom`
|
|
8
|
+
* Cliente HTTP baseado em got
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Instalação
|
|
4
13
|
|
|
5
14
|
```bash
|
|
6
|
-
bun
|
|
15
|
+
bun add @wargas/crawler
|
|
7
16
|
```
|
|
8
17
|
|
|
9
|
-
|
|
18
|
+
ou usando npm:
|
|
10
19
|
|
|
11
20
|
```bash
|
|
12
|
-
|
|
21
|
+
npm install @wargas/crawler
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
# Uso básico
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { Crawler } from "@wargas/crawler";
|
|
30
|
+
|
|
31
|
+
const crawler = Crawler.factory();
|
|
32
|
+
|
|
33
|
+
await crawler.client.get("https://example.com");
|
|
34
|
+
|
|
35
|
+
console.log(crawler.html);
|
|
36
|
+
|
|
37
|
+
console.log(
|
|
38
|
+
crawler.document.querySelector("title")?.textContent
|
|
39
|
+
);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
# Cookies persistentes
|
|
45
|
+
|
|
46
|
+
Os cookies são armazenados automaticamente no arquivo:
|
|
47
|
+
|
|
48
|
+
```txt
|
|
49
|
+
cookies.json
|
|
13
50
|
```
|
|
14
51
|
|
|
15
|
-
|
|
52
|
+
Isso permite manter sessão entre execuções.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
# Limpar cookies
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
await crawler.removeAllCookies();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
# Acessando o DOM
|
|
65
|
+
|
|
66
|
+
Como o HTML é convertido automaticamente usando `linkedom`, é possível utilizar APIs similares ao navegador:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
const links = crawler.document.querySelectorAll("a");
|
|
70
|
+
|
|
71
|
+
for (const link of links) {
|
|
72
|
+
console.log(link.getAttribute("href"));
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
# Configurações atuais
|
|
79
|
+
|
|
80
|
+
A instância do `got` é criada com:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
followRedirect: false
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Ou seja:
|
|
87
|
+
|
|
88
|
+
* redirects não são seguidos automaticamente
|
|
89
|
+
* cookies são persistidos
|
|
90
|
+
* HTML é parseado automaticamente após cada resposta
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
# Possíveis melhorias
|
|
95
|
+
|
|
96
|
+
* Suporte a proxy
|
|
97
|
+
* Retry automático
|
|
98
|
+
* Timeout configurável
|
|
99
|
+
* User-Agent customizado
|
|
100
|
+
* Suporte a certificados digitais
|
|
101
|
+
* Suporte a HTTP2
|
|
102
|
+
* Métodos helper (`get`, `post`, `login`, etc.)
|
|
103
|
+
* Cache de páginas
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
# Licença
|
|
108
|
+
|
|
109
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wargas/crawler",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"module": "index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"private": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/wargas/crawler.git"
|
|
11
|
+
},
|
|
8
12
|
"scripts": {
|
|
9
13
|
"build": "bun build index.ts --target node --outdir dist",
|
|
10
14
|
"publish": "npm publish --tag latest --access public"
|