# jxltaxspider
**Repository Path**: tufeiping/jxltaxspider
## Basic Information
- **Project Name**: jxltaxspider
- **Description**: 互联网三方数据工具
- **Primary Language**: NodeJS
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 3
- **Created**: 2017-06-13
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# YonyouTaxSpider (互联网三方数据工具)
#### 这个系统是一个互联网三方数据获取工具,由于在github上没有找到合适的,所以只好自己写一个简单的,虽然是为税务(垂直行业)编写的,但适用于其他行业,提供了一个小的系统框架。
**目前系统包含以下部分**
> 1. 爬虫
> 2. 网页展示
> 3. 数据保存及导出
> 4. 任务调度和测试接口
* 系统采用mongodb数据库
* 数据库连接配置为 db/index.js 文件 的 connect_prop 对象
* 开发环境: node v6.5.0[v6.9.0], visule studio code v1.7.1
* 测试运行环境: `Linux Ubuntu 16.04.1 LTS` 和 `Windows 8`
* 使用开发语言: TypeScript
--------------
* 环境配置
> npm install
> cd src
> npm i -g @types/node
> npm install
--------------
* 编译系统
> cd ..
> npm run deploy
--------------
* 运行系统
> node index.js # 在项目目录运行,将src中的依赖等环境和web内容拷贝到dist目录
> cd dist # 进入dist(编译后)目录
> node index.js --help
> node index.js -w # 以web形式启动
> node index.js -n # 获取新的网络信息,参数为modules中爬虫文件的名称
> node index.js -t -n # 结合-n参数可以单独测试某个爬虫
* 备注:windows平台需要单独安装 `npm i -g q` 如果有其他错误,请npm下载对应的依赖库,如果本机没有安装过 **TypeScript**,请单独安装 `npm install -g typescript tsc`
--------------
## 系统支持Web方式浏览和基本查询
> node index.js -w # 以web 服务方式启动
> http://localhost:3000 # 默认监听3000端口
> http://localhost:3000/exportData?collection=数据表(collection)的名称
-------------
## 部署方式
* 将 node index.js -w 启动后,就可以通过网页访问
* 将 node index.js -a 放在定时任务(Windows)或者crontab(Linux),按指定间隔定时执行
* 由于爬虫的特殊性,有可能会造成进程奔溃(crash),所以,请配合外部deamon系统,保持进程在退出后能自动重启,爬虫框架会保证重启后的状态resume
## 工具的编写和调试
建议采用 Visual Studio Code IDE 开发爬虫部分,所有的爬虫采用 **TypeScript** 进行封装和编写。
## 爬虫的编写(TypeScript)
所有的爬虫都是采用 **TypeScript** 编写,可以用最简单的爬虫模板,如下所示:
//工具类 const utils = require('../utils'); import {Base, Item} from "./base"; const srfdc_url = "http://www.jxsrfdc.com/Publish/xmgs.aspx"; class demo_spider extends Base { arrs: any[]; constructor() { super(); this.name = "上饶房地产信息网"; this.encode = "gb2312"; this.arrs = []; } // 系统回调函数 getPageCount(): number { var cnt = 0; return cnt; } // 系统回调函数 getItems(pageIndex: number): Item[] { var _url = "http://www.jxsrfdc.com/Publish/" + this.arrs[pageIndex].href; this.spider.getSync(_url); var item = this.buildItem("fdcxx"); var result: Item[] = [item]; return result; }; } export = new demo_spider();* 系统返回的Item对象,请用爬虫基类的 `buildItem()` 或者 `buildItem('保存到的Collection名称')` 函数创建,以便统一返回对象  > 关于版权:MIT 您可以随意使用,但在使用的时候,去除用友相关标示,并对**用友软件**心存感激即可! > Sunny