# ts网络爬虫 **Repository Path**: heda321/ts-web-crawler ## Basic Information - **Project Name**: ts网络爬虫 - **Description**: 使用ts语法实现网络爬虫 - **Primary Language**: TypeScript - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2023-12-04 - **Last Updated**: 2023-12-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 初始化配置 一、npm 项目初始化 ```bash npm init -y ``` 二、ts 项目初始化 ```bash tsc --init ``` 三、安装 typescript ```bash cnpm install typescript -D ``` 四、安装 ts-node 服务器 ```bash cnpm install ts-node -D ``` 五、安装 superagent 插件,在 node 中能发送请求获取数据 ```bash cnpm install superagent -D ``` 六、安装 superagent 翻译为 ts 后的文件 ```bash cnpm install @types/superagent -D ``` 七、安装 cheerio 插件,分析 html 文件 ```bash cnpm install cheerio --save ``` 八、安装 cheerio 翻译文件 ```bash cnpm install @types/cheerio -D ``` 九、package.json 的文件配置 ```json { "scripts": { // 单独编译运行指定的 ts 文件,运行 ts-node 会去走 tsconfig.json 内的文件配置 "start_ts": "ts-node ./src/crowller.ts", // 编译所有 ts 文件,运行该命令后系统会去找 tsconfig.json 内的文件配置,对编译进行控制 // 只有在执行 tsc 命令并且后面不跟任何参数时才会执行 tsconfig.json 内的文件配置,如果 tsc 后面有参数则不会走 tsconfig.json 内的文件配置 "build": "tsc", // 实时监测 ts 文件变化,并进行实时编译 "dev:build_w": "tsc -w", // 实时监控 js 文件变化并进行编译运行 "dev:start": "nodemon node ./build/crowller.js", // "tsc &&" 指令是先执行 tsc 指令生成 ./build/crowller.js 文件后再执行 concurrently npm:dev:* 防止由于找不到 ./build/crowller.js 文件发生报错 "dev": "tsc && concurrently npm:dev:*" }, // node 监控器配置 "nodemonConfig": { // 忽略对哪些文件的监控 "ignore": ["data/*"] } } ``` 十、tsconfig.json 文件配置(tsc 的编译配置文件) ```json { // 编译后输出的文件位置 "outDir": "./build" } ``` 十一、安装 node 即时监测工具,该工具只监控对 js 文件的变化 ```bash cnpm install nodemon -D ``` 十二、安装 node 多指令并行执行工具 ```bash cnpm install concurrently -D ``` 十三、使用 parcel 直接编译并运行 html 内引用的 ts 文件(非必要) ```bash cnpm install parcel@next -D ``` 安装好之后对 package.json 文件做如下配置: ```json { "scripts": { "parcel": "parcel ./src/index.html" } } ``` 启动 parcel 后本地会直接起一个服务器,可直接访问