admin管理员组

文章数量:1578605

代码地址如下:
http://www.demodashi/demo/12368.html

1 概述

本实例主要使用Node.js去抓取电影的节目单,方便大家使用下载。

2 node package

  1. fs
  2. cheerio
  3. superagent
  4. superagent-charset
  5. express
  6. path

fs 用来读写文件
cherrio 类似jquery
superagent (ajax http模块)
superagent-charset 解决中文乱码问题
express 搭建server
path 路径

统一安装这些包,可以使用一下命令:

npm i express cheerio superagent superagent-charset path fs --save-dev

如果想深入了解这些包 可以去下面这个网址了解下
find package

3 步骤

第一步:

利用express 搭建本地服务

const app = require('express')();
const port = 3000;

app.get('/', (req, res)=>{
    res.send('hello world');
});

app.listen(port, ()=>{
    console.log('listening port on', port);
});

打开浏览器 输入 localhost:3000

看到下面页面,说明初步成功

第二步

先试用superagent(http模块)去获取页面的数据,然后用cheerio(类似jquery)去获取页面数据。
具体代码如下

var item = [];
function getMovies() {
   
    item = [];
    

本文标签: 电影节目单新上链接天堂