File tree 1 file changed +3
-4
lines changed
1 file changed +3
-4
lines changed Original file line number Diff line number Diff line change @@ -28,17 +28,16 @@ import XCrawl from 'x-crawl'
28
28
29
29
// 2.创建一个爬虫实例
30
30
const myXCrawl = new XCrawl({
31
- baseUrl: ' https://www.bilibili.com' ,
32
31
timeout: 10000, // 超时时间
33
32
intervalTime: { max: 6000, min: 2000 } // 控制请求频率
34
33
})
35
34
36
35
// 3.调用 fetchHTML API 爬取 HTML
37
- myXCrawl.fetchHTML(' /guochuang/' ).then(( res) => {
36
+ myXCrawl.fetchHTML(' https://www.bilibili.com /guochuang/' ).then(( res) => {
38
37
const { jsdom } = res.data // 默认使用了 JSDOM 库解析 HTML
39
38
40
39
// 3 .1 .获取轮播图片的 src
41
- const imgSrc: string[] = []
40
+ const imgSrc = []
42
41
const recomEls = jsdom.window.document.querySelectorAll('.chief-recom-item')
43
42
recomEls.forEach((item) => imgSrc.push(item.querySelector('img').src))
44
43
@@ -48,7 +47,7 @@ myXCrawl.fetchHTML('/guochuang/').then((res) => {
48
47
})
49
48
` ` `
50
49
51
- ** 注意:** 请勿随意爬取,这里只是为了演示爬取过程 ,并将请求频率控制在 6000ms 到 2000ms 内。
50
+ ** 注意:** 请勿随意爬取,这里只是为了演示如何使用 XCrawl ,并将请求频率控制在 6000ms 到 2000ms 内。
52
51
53
52
# # 核心概念
54
53
You can’t perform that action at this time.
0 commit comments