Giter Site home page Giter Site logo

ecitlm / node-spliderapi Goto Github PK

View Code? Open in Web Editor NEW
850.0 22.0 216.0 5.8 MB

基于node+express爬虫 API接口项目,包括全国高校信息、成语诗歌、星座运势、历史的今天、音乐数据接口、图片壁纸、搞笑视频、热点新闻资讯 详情接口数据

License: MIT License

JavaScript 96.73% HTML 3.27%
express expressjs mysql nodejs

node-spliderapi's Introduction

Express

项目基于express+sequelize+mysql+express-validator 基于node+express爬虫 API接口项目,包括全国高校信息、成语诗歌、星座运势、历史的今天、音乐数据接口、图片壁纸、搞笑视频、热点新闻资讯 详情接口数据

  • express
  • sequelize
  • mysql
  • express-validator参数表单校验
  • 使用cheerio解析爬虫页面
  • 集成ejs模板
  • 集成swaggerUI接口文档
  • nodemon项目开发动态热更新
  • dotenv管理配置系统参数
  • 包含接口sign请求验证
  • log4js 错误日志收集

环境要求

需要安装node环境,mysql数据库

部署运行

$ git clone https://github.com/ecitlm/Node-SpliderApi.git
$ npm install
#  start project dev
$ npm run dev
# starting prd
$ npm run prd
#localhost:3001

服务器部署

在服务器中使用 pm2node 服务进行进程守护

#启动进程/应用
pm2 start npm --watch --name tools -- run prd
pm2 restart tools
pm2 stop tools
pm2 delete tools

数据库

mysql中包含、唐诗300、成语、历史的今天、星座运势(聚合平台数据-需要申请自己的APPCODE)、用户表等数据 项目目录bak-file文件夹可查看

接口文档

启动项目之后http://localhost:3001/api-docs/ 可查看接口文档页面 api.png api2.png

错误码说明

状态码 含义 备注
200 响应正常
1001 参数无效、如一个不存在的id
1002 参数为空、验证不通过、参数类型错误
1003 请求签名异常、非法
404 请求不存在
405 请求方式错误
9999 第三方接口请求异常
500 系统异常

感谢JetBrains 的支持

JetBrains:https://www.jetbrains.com/?from=Node-SpliderApi

node-spliderapi's People

Contributors

ecitlm avatar wangzianan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-spliderapi's Issues

httpServer.js function bug.

function httpGet(host, data, path, status) {
  let options = {
    host: host,
    port: 80,
    // path missing '?' symbol make path different. 
    path: path + querystring.stringify(data),
    method: 'GET',
    encoding: null,
    headers: {
      'Content-Type': 'application/json',
      'User-Agent':
        'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36'
    }
  }

  if (status) {
    http = require('https')
    options.port = 443
  }

  return new Promise(function(resolve, reject) {
    let body = ''
    let get_req = http.request(options, function(response) {

      response.on('data', function(chunk) {
        body += chunk
      })

      response.on('end', () => {
        resolve(body)
      })

      response.on('error', err => {
        reject(err)
      })
    })
    get_req.end()
  })
}
function httpPost(host, data, path, status) {
  // SyntaxError: Identifier 'data' has already been declared, remove let declaration.
  let data = querystring.stringify(data)
  let options = {
    host: host,
    port: '80',
    path: path,
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'User-Agent':
        'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36',
      'Content-Length': Buffer.byteLength(data) 
    }
  }

  if (status) {
    http = require('https')
    options.port = 443
  }
  return new Promise(function(resolve, reject) {
    let body = ''
    let post_req = http.request(options, function(response) {

      response.on('data', function(chunk) {
        body += chunk
      })

      response.on('end', () => {
        resolve(body)
      })

      response.on('error', err => {
        reject(err)
      })
    })

    post_req.write(data)
    post_req.end()
  })
}

从前端请求发送到最后入数据库流程都有哪些?

我这边直接使用项目作为后端部分,然后另外启动一个前端项目A,proxy指向了你这个项目的启动ip地址,调用对应的接口。鉴于项目内使用的东西较多,所以先使用了最简单的接口/api/wx-login,来尝试登录功能。
我觉得逻辑来说,步骤应该是:
1、当前node服务器启动后设置了监听当前项目ip的请求
2、在我的前端项目A发送对应IP请求后,你这个项目监听到对应的req请求
3、根据请求走到了router.js里面找对应的api
4、根据path: '/api/wx-login',调用对应的controller为controller/we-app/getUserInfo
5、在对应controller(getUserInfo)中处理业务,然后调用model层
6、在model层里面去调用类dao层,然后去查数据

但是我实际操作的时候问题是,连controller都没有进。直接被拦截器拦截了,我在网上查了express的app.use使用相关的内容,大概理解为什么被拦截了,不过还是想请教下,从前端请求发送到最后入数据库,除了上面我写的“步骤1-6”,还有什么其他步骤是我忽略的么,有的话能否辛苦补充一下~
谢谢

反馈3个问题(接口不太稳定?)

【问题一】

3.1 新闻列表:http://localhost:3001/api/news_list/1
新闻类型参数type失效。返回的全是“社会”类的新闻。

【问题二】

1.1 最新前 10 天日报列表:http://localhost:3001/api/daily_list
我用了一下午好好的,突然开始返回
{"code":404,"msg":"网络好像有,点问题"}
貌似是接口挂掉了(用代理也打不开)
(看来我得手动保存下JSON数据ORZ)

【问题三】

数据库连接好像没什么用?建议删了这个。

where is the db schema?

hi, i've cloned your repo and tried to run it.

unfortunately, it depends on mysql db. and i can't find where is the db schema to set up the mysql thing.

could you give me a hint.

thankx

不能运行,修改后得不到数据

module.js:457
throw err;
^

Error: Cannot find module 'html-entities'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object. (/Users/kyle/node/SpliderApi/routes/api/job/job_info.js:13:42)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)

bogon:SpliderApi kyle$ node app.js
app start success port:3001
[query] - :Error: connect ECONNREFUSED 127.0.0.1:3306

http://127.0.0.1:3000/

打开后只有
欢迎进入IT开发者--Nodejs云服务平台 和 fork me on Github
这几个字 ,没有地方点击

process.env.ApiSign 这个无法设置

api-sign.js里面判断process.env.ApiSign === 'false'这个逻辑是没有用的,因为process.env.ApiSign打印返回的是undefined,上网上查了下,process.env对象的值是不能够直接设置的,只能以如下显示的方式进行设置
import { env } from 'node:process';
env.foo = 'bar';
console.log(env.foo);
参考:
http://nodejs.cn/api/process/process_env.html

讨论下,官方的app.get('/api')捕获不到对应的路径问题

controller中拦截post请求,源代码的拦截结构如下:
app.post('/', (req, res) => {});
这种方式当然是没有问题的,可以正常的。
但是如果我想拦截的是path不是'/',而是其他的,比如'/api'之类的,又或者我想在同一个controller中去同时拦截注册和登录,预期写法如下:
app.post('/api/reg', (req, res) => {});
app.post('/api/login', (req, res) => {});
这种方式处理的话,我查了express官方文档,是支持的,官方文档链接如下:
https://expressjs.com/en/guide/routing.html

123
但是实际上,我以app.post('/api', (req, res) => {});这种方式写的时候,根本无法拦截到请求,会直接返回给前端cannot post '/api/xxxxx'之类的。中间我也尝试换了多个写法都不行,只有最初的app.post('/', (req, res) => {});可以

那么现在问题来了,其实我可以直接一个请求一个conntorller,但是基于对官方文档的信任又感觉半途而废很可惜,所以发出来和大家讨论下,谁用的比较多或者比较了解的望不吝指教

注释中有笔误~

2.框架 top 排行榜

说明:获取前前端框架排名,我们可以看看web前端世界的框架排名

说明中多打了一个“前”

请问一下有花瓣的其他分类接口吗?

请问一下有花瓣的其他分类接口吗?
花瓣的美女分类也分的不准确,就和刷新一样。
还有两边的文档调用例子有些用不了,有些这边有那边没有

启动报错

[query] - :Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
是不是还需要安装mysql

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.