Skip to content

Commit b7a4936

Browse files
committed
爬取数据测试
1 parent d66b3c0 commit b7a4936

File tree

6 files changed

+154
-38
lines changed

6 files changed

+154
-38
lines changed

script/start.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import terserPlugin from '@rollup/plugin-terser'
33
import runPlugin from '@rollup/plugin-run'
44

55
export default {
6-
input: 'test/start.ts',
6+
input: 'test/start/index.ts',
77
output: {
8-
file: 'test/start.js',
8+
file: 'test/start/index.js',
99
format: 'cjs'
1010
},
1111
plugins: [tsPlugin(), terserPlugin(), runPlugin({ stdin: { clear: true } })]

test/start.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/start.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

test/start/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/start/index.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import path from 'node:path'
2+
3+
import { fetch, fetchFile } from '../../src'
4+
5+
import { IRequestConfig } from '../../src/types'
6+
import { IAreaRoom, IBRecommend } from './types'
7+
8+
// 1. 爬取 房间数据
9+
// https://github.com/coder-hxl/airbnb-api
10+
11+
function areaRoomData() {
12+
fetch<IAreaRoom>({
13+
requestConifg: {
14+
url: 'http://localhost:9001/api/area/阳江市?name=123;age=18',
15+
method: 'POST',
16+
data: {
17+
type: 'plus',
18+
offset: 0,
19+
size: 20
20+
},
21+
timeout: 10000
22+
}
23+
}).then((res) => {
24+
const { id, name, pictureUrls } = res.data.list[0]
25+
console.log(id, name)
26+
const requestConifg: IRequestConfig[] = pictureUrls.map((url) => ({
27+
url,
28+
method: 'GET'
29+
}))
30+
fetchFile({
31+
requestConifg,
32+
intervalTime: { max: 3000, min: 2000 },
33+
fileConfig: { storeDir: path.resolve(__dirname, './upload') }
34+
})
35+
})
36+
}
37+
38+
// areaRoomData()
39+
40+
// ==================================================
41+
42+
// 2. 爬取 b站首页推荐视频 的封面图
43+
/*
44+
https://api.bilibili.com/x/web-interface/wbi/index/top/feed/rcmd?y_num=5&fresh_type=3&feed_version=V8&fresh_idx_1h=1&fetch_row=1&fresh_idx=1&brush=0&homepage_ver=1&ps=10&outside_trigger=&w_rid=921db33671365ec8b9f7cab1971a3834&wts=1674553870
45+
*/
46+
47+
function bilibiliRecommendData() {
48+
fetch<IBRecommend>({
49+
requestConifg: {
50+
url: 'https://api.bilibili.com/x/web-interface/wbi/index/top/feed/rcmd',
51+
method: 'GET',
52+
params: {
53+
y_num: 5,
54+
fresh_type: 3,
55+
feed_version: 'V8',
56+
fresh_idx_1h: 1,
57+
fetch_row: 1,
58+
fresh_idx: 1,
59+
brush: 0,
60+
homepage_ver: 1,
61+
ps: 10,
62+
outside_trigger: '',
63+
w_rid: '2e4be8e9830ecd780c5b0ff2bef805c9',
64+
wts: 1674556002
65+
},
66+
headers: {}
67+
}
68+
}).then((res) => {
69+
const pictureUrls: IRequestConfig[] = res.data.item.map((item) => ({
70+
url: item.pic,
71+
method: 'GET'
72+
}))
73+
74+
fetchFile({
75+
requestConifg: pictureUrls,
76+
intervalTime: { max: 3000, min: 2000 },
77+
fileConfig: { storeDir: path.resolve(__dirname, './upload') }
78+
})
79+
})
80+
}
81+
bilibiliRecommendData()

test/start/types.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
export interface IAreaRoom {
2+
code: number
3+
data: {
4+
list: {
5+
id: number
6+
name: string
7+
price: number
8+
type: string
9+
coverUrl: string
10+
lng: number
11+
lat: number
12+
starRating: number
13+
reviewsCount: number
14+
bedTypes: string[]
15+
scoreDesc: string
16+
pictureUrls: string[]
17+
}[]
18+
totalCount: number
19+
}
20+
}
21+
22+
export interface IBRecommend {
23+
code: number
24+
message: string
25+
ttl: number
26+
data: {
27+
item: IBRecommendItem[]
28+
business_card: any
29+
floor_info: any
30+
user_feature: any
31+
preload_expose_pct: number
32+
preload_floor_expose_pct: number
33+
mid: number
34+
}
35+
}
36+
37+
export interface IBRecommendItem {
38+
id: number
39+
bvid: string
40+
cid: number
41+
goto: string
42+
uri: string
43+
pic: string
44+
title: string
45+
duration: number
46+
pubdate: number
47+
owner: {
48+
mid: number
49+
name: string
50+
face: string
51+
}
52+
stat: {
53+
view: number
54+
like: number
55+
danmaku: number
56+
}
57+
av_feature: any
58+
is_followed: number
59+
rcmd_reason: {
60+
reason_type: number
61+
content?: string
62+
}
63+
show_info: number
64+
track_id: string
65+
pos: number
66+
room_info: any
67+
ogv_info: any
68+
business_info: any
69+
is_stock: number
70+
}

0 commit comments

Comments
 (0)