diff --git a/package.json b/package.json index 55ab452..39e7635 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "dependencies": { "axios": "^1.7.9", "cheerio": "^1.0.0", + "g": "^2.0.1", "puppeteer": "^24.2.1", "uuid": "^11.0.5" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index aa70987..5b60493 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: cheerio: specifier: ^1.0.0 version: 1.0.0 + g: + specifier: ^2.0.1 + version: 2.0.1 puppeteer: specifier: ^24.2.1 version: 24.2.1(typescript@5.7.3) @@ -346,6 +349,9 @@ packages: function-bind@1.1.2: resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} + g@2.0.1: + resolution: {integrity: sha512-Fi6Ng5fZ/ANLQ15H11hCe+09sgUoNvDEBevVgx3KoYOhsH5iLNPn54hx0jPZ+3oSWr+xajnp2Qau9VmPsc7hTA==} + get-caller-file@2.0.5: resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} engines: {node: 6.* || 8.* || >= 10.*} @@ -976,6 +982,8 @@ snapshots: function-bind@1.1.2: {} + g@2.0.1: {} + get-caller-file@2.0.5: {} get-intrinsic@1.2.7: diff --git a/src/index.ts b/src/index.ts index 7932f17..8c5cab3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ import { fetchData } from "./link"; function main() { console.log("Hello, this is the main function!"); fetchData("AI写作工具") + // test() } main(); diff --git a/src/link/index.ts b/src/link/index.ts index 9b20370..21ebf4d 100644 --- a/src/link/index.ts +++ b/src/link/index.ts @@ -28,7 +28,7 @@ export async function fetchData(typeName: string) { // 提取工具卡片数据 const toolsData = [] as any; - $('.url-card').each(async (index: any, element: any) => { + for (const element of $('.url-card')) { const name = $(element).find('.url-info strong').text().trim(); const tempLink = $(element).find('a').attr('href') as string; const description = $(element).find('.url-info p').text().trim(); @@ -41,7 +41,7 @@ export async function fetchData(typeName: string) { } // 假设工具的类别是固定的,比如 "AI写作工具" const type = typeName; - const priority = index + 1; // 根据索引来定义优先级 + const priority = 1; // 根据索引来定义优先级 const addTime = Date.now(); const logoLink = await downloadImage(_originLink) // console.log(logoLink); @@ -58,8 +58,10 @@ export async function fetchData(typeName: string) { addTime, }; - await toolsData.push(toolData); - }); + toolsData.push(toolData); + console.log('完成' ); + + } console.log(toolsData); diff --git a/src/link/test.ts b/src/link/test.ts new file mode 100644 index 0000000..a651e72 --- /dev/null +++ b/src/link/test.ts @@ -0,0 +1,33 @@ +import { resolve } from "path" + +function asyncFunction() { + return new Promise(resolve => { + setTimeout(() => { + console.log('time out'); + + resolve(1) + }, 1000) + }) +} +export default async function test() { + const list = [1, 2, 3] + const result: number[] = []; + await (async () => { + console.log('前'); + + list.forEach(async (val) => { + result.push(val) + console.log('-前'); + + await asyncFunction() + result.push(val) + console.log('-后'); + + + }) + console.log('后'); + + })() + console.log(result); + +} \ No newline at end of file