-
Notifications
You must be signed in to change notification settings - Fork 0
/
debugger.ts
58 lines (56 loc) · 1.91 KB
/
debugger.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { crawlFromUrl, CrawlerUrlOptions } from './src/index.js';
const options: CrawlerUrlOptions = {
url: 'https://www.bswtan.com/modules/article/search.php',
fetchOptions: {
method: 'POST',
body: 'searchkey=灵境',
headers: { 'Content-Type': 'application/x-www-form-urlencoded', Host: 'www.biqukun.info' },
},
rules: {
list: {
selector: '#main>.grid>tbody>tr:nth-child(n+2)',
handlers: [
{
method: 'map',
args: [
{
name: {
handlers: [{ method: 'find', args: ['td:nth-child(1)'] }, { method: 'text' }, { method: 'trim' }],
},
bookUrl: {
handlers: [
{ method: 'find', args: ['td:nth-child(1)>a'] },
{ method: 'attr', args: ['href'] },
{ method: 'prefix', args: ['https://www.bswtan.com'] },
],
},
latestChapterName: {
handlers: [{ method: 'find', args: ['td:nth-child(2)'] }, { method: 'text' }, { method: 'trim' }],
},
latestChapterUrl: {
handlers: [
{ method: 'find', args: ['td:nth-child(2)>span>a'] },
{ method: 'attr', args: ['href'] },
{ method: 'prefix', args: ['https://www.bswtan.com'] },
],
},
author: {
handlers: [{ method: 'find', args: ['td:nth-child(3)'] }, { method: 'text' }, { method: 'trim' }],
},
updateTime: {
handlers: [{ method: 'find', args: ['td:nth-child(4)'] }, { method: 'text' }, { method: 'trim' }],
},
},
],
},
{
method: 'find',
args: ['name', '灵境行者'],
},
],
},
},
};
crawlFromUrl(options).then((res) => {
console.log(JSON.stringify(res.data));
});