@@ -101,7 +101,6 @@ npm install x-crawl
101
101
102
102
` ` ` js
103
103
// 1.导入模块 ES/CJS
104
- import path from ' node:path'
105
104
import xCrawl from ' x-crawl'
106
105
107
106
// 2.创建一个爬虫实例
@@ -125,13 +124,7 @@ myXCrawl.startPolling({ d: 1 }, () => {
125
124
imgEls.forEach((item) => requestConfig.push(`https:${item.src} `))
126
125
127
126
// 调用 crawlFile API 爬取图片
128
- myXCrawl.crawlFile({
129
- requestConfig,
130
- fileConfig: { storeDir: path.resolve(__dirname, ' ./upload' ) }
131
- })
132
-
133
- // 关闭浏览器
134
- browser.close ()
127
+ myXCrawl.crawlFile({ requestConfig, fileConfig: { storeDir: ' ./upload' } })
135
128
})
136
129
})
137
130
` ` `
@@ -259,7 +252,6 @@ myXCrawl.crawlData({ requestConfig }).then(res => {
259
252
通过 [crawlFile()](# crawlFile) 爬取文件数据
260
253
261
254
` ` ` js
262
- import path from ' node:path'
263
255
import xCrawl from ' x-crawl'
264
256
265
257
const myXCrawl = xCrawl({
@@ -273,7 +265,7 @@ myXCrawl
273
265
.crawlFile({
274
266
requestConfig,
275
267
fileConfig: {
276
- storeDir: path.resolve(__dirname, ' ./upload' ) // 存放文件夹
268
+ storeDir: ' ./upload' // 存放文件夹
277
269
}
278
270
})
279
271
.then(( fileInfos) => {
@@ -298,8 +290,6 @@ myXCrawl.startPolling({ h: 2, m: 30 }, (count, stopPolling) => {
298
290
// crawlPage/crawlData/crawlFile
299
291
myXCrawl.crawlPage('https://xxx.com').then(res => {
300
292
const { jsdom, browser, page } = res
301
-
302
- browser.close()
303
293
})
304
294
})
305
295
```
@@ -413,7 +403,7 @@ const requestConfig = [ 'https://xxx.com/xxxx', 'https://xxx.com/xxxx', 'https:/
413
403
myXCrawl
414
404
.crawlFile({
415
405
requestConfig,
416
- fileConfig: { storeDir: path.resolve(__dirname, './upload') }
406
+ fileConfig: { storeDir: './upload' }
417
407
})
418
408
.then((fileInfos) => {
419
409
console.log('Promise: ', fileInfos)
@@ -423,7 +413,7 @@ myXCrawl
423
413
myXCrawl.crawlFile(
424
414
{
425
415
requestConfig,
426
- fileConfig: { storeDir: path.resolve(__dirname, './upload') }
416
+ fileConfig: { storeDir: './upload' }
427
417
},
428
418
(fileInfo) => {
429
419
console.log('Callback: ', fileInfo)
@@ -435,7 +425,7 @@ myXCrawl
435
425
.crawlFile(
436
426
{
437
427
requestConfig,
438
- fileConfig: { storeDir: path.resolve(__dirname, './upload') }
428
+ fileConfig: { storeDir: './upload' }
439
429
},
440
430
(fileInfo) => {
441
431
console.log('Callback: ', fileInfo)
@@ -573,7 +563,6 @@ function crawlFile: (
573
563
#### 示例
574
564
575
565
```js
576
- import path from 'node:path'
577
566
import xCrawl from 'x-crawl'
578
567
579
568
const myXCrawl = xCrawl({
@@ -588,7 +577,7 @@ myXCrawl
588
577
.crawlFile({
589
578
requestConfig,
590
579
fileConfig: {
591
- storeDir: path.resolve(__dirname, './upload') // 存放文件夹
580
+ storeDir: './upload' // 存放文件夹
592
581
}
593
582
})
594
583
.then((fileInfos) => {
0 commit comments