chore: 初始化文档站仓库
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
// 使用无头浏览器检索资料:按关键词搜索并保存结果页可见文本到 refs/。
|
||||
import { mkdir, writeFile } from 'node:fs/promises'
|
||||
import { resolve } from 'node:path'
|
||||
import { launchBrowser, newContext } from './browser.js'
|
||||
import { ROOT } from './config.js'
|
||||
|
||||
/** 待检索的关键词:输出文件名与搜索词 */
|
||||
const SEARCHES: Array<[string, string]> = [
|
||||
['bing_alipay2', '支付宝 我的 账单 开具交易流水证明 下载 csv 邮箱'],
|
||||
['bing_meituan2', '美团App 我的 钱包 账单 下载账单 导出 3个月'],
|
||||
['bing_bocom2', '交通银行 个人手机银行 我的账户 交易明细 电子版 导出'],
|
||||
]
|
||||
|
||||
const OUT_DIR = resolve(ROOT, 'refs')
|
||||
|
||||
async function main(): Promise<void> {
|
||||
await mkdir(OUT_DIR, { recursive: true })
|
||||
const browser = await launchBrowser()
|
||||
const context = await newContext(browser, { width: 1440, height: 1400 })
|
||||
const page = await context.newPage()
|
||||
try {
|
||||
for (const [name, keyword] of SEARCHES) {
|
||||
const url = `https://cn.bing.com/search?q=${encodeURIComponent(keyword)}&setlang=zh-CN`
|
||||
try {
|
||||
await page.goto(url)
|
||||
await page.waitForTimeout(6000)
|
||||
for (let i = 0; i < 4; i++) {
|
||||
await page.evaluate(() => window.scrollBy(0, document.body.scrollHeight / 4))
|
||||
await page.waitForTimeout(1000)
|
||||
}
|
||||
const text = await page.evaluate(() => document.body.innerText)
|
||||
await writeFile(resolve(OUT_DIR, `${name}.txt`), text, 'utf8')
|
||||
console.log(`[OK] ${name} -> ${text.length} chars`)
|
||||
} catch (err) {
|
||||
console.log(`[FAIL] ${name}: ${err}`)
|
||||
}
|
||||
await page.waitForTimeout(8000)
|
||||
}
|
||||
} finally {
|
||||
await context.close()
|
||||
await browser.close()
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error('FAIL', err)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user