Skip to content

Commit b33b8a3

Browse files
committed
test: change of name
1 parent 9c55449 commit b33b8a3

File tree

9 files changed

+208
-61
lines changed

9 files changed

+208
-61
lines changed

script/dev.js

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/index.ts',
6+
input: `test/dev/index.ts`,
77
output: {
8-
file: 'test/start/index.js',
8+
file: `test/dev/index.js`,
99
format: 'es'
1010
},
1111
plugins: [tsPlugin(), terserPlugin(), runPlugin({ stdin: { clear: true } })]
File renamed without changes.

test/dev/envConfig.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import dotenv from 'dotenv'
2+
import { fileURLToPath } from 'node:url'
3+
4+
const pathResolve = (dirPath: string) =>
5+
fileURLToPath(new URL(dirPath, import.meta.url))
6+
7+
dotenv.config({ path: pathResolve('.env') })
8+
9+
export const { BASE_URL, API_KEY } = process.env

test/dev/index.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import path from 'node:path'
2+
import { createCrawl, createCrawlOpenAI } from 'x-crawl'
3+
import { fileURLToPath } from 'node:url'
4+
5+
import { BASE_URL, API_KEY } from './envConfig'
6+
7+
const pathResolve = (dirPath: string) =>
8+
fileURLToPath(new URL(dirPath, import.meta.url))
9+
10+
const crawlOpenAIApp = createCrawlOpenAI({
11+
clientOptions: { baseURL: BASE_URL, apiKey: API_KEY }
12+
})
13+
14+
const crawlApp = createCrawl({
15+
crawlPage: { puppeteerLaunchOptions: { headless: true } }
16+
})
17+
18+
crawlApp.crawlPage('https://www.airbnb.cn/s/select_homes').then(async (res) => {
19+
const { page, browser } = res.data
20+
21+
// await page.waitForSelector('.g1nr81q6')
22+
// const sectionHTML = await page.$eval('.g1nr81q6 ', (el) => el.innerHTML)
23+
await page.waitForSelector(
24+
'.g1nr81q6 > a:nth-child(1), .g1nr81q6 > a:nth-child(2)'
25+
)
26+
const sectionHTML = await page.$$eval(
27+
'.g1nr81q6 > a:nth-child(1), .g1nr81q6 > a:nth-child(2) ',
28+
(els) => els.reduce((p, v) => p + v.innerHTML, '')
29+
)
30+
31+
const srcResult = await crawlOpenAIApp.parseElements<{ src: string }>(
32+
sectionHTML,
33+
`获取 img 的 src`
34+
)
35+
36+
console.log(srcResult)
37+
38+
crawlApp.crawlFile({
39+
targets: srcResult.elements.map((item) => item.src),
40+
storeDirs: pathResolve('upload')
41+
})
42+
43+
browser.close()
44+
})

test/start/package.json renamed to test/dev/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "start",
2+
"name": "dev",
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",
@@ -12,5 +12,10 @@
1212
"license": "ISC",
1313
"devDependencies": {
1414
"dotenv": "^16.4.5"
15+
},
16+
"dependencies": {
17+
"dev": "link:",
18+
"ora": "^8.0.1",
19+
"signal-exit": "^4.1.0"
1520
}
1621
}

test/dev/pnpm-lock.yaml

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

test/start/envConfig.ts

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

test/start/index.ts

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

test/start/pnpm-lock.yaml

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

0 commit comments

Comments
 (0)