admin管理员组文章数量:1578594
代码地址如下:
http://www.demodashi/demo/12368.html
1 概述
本实例主要使用Node.js去抓取电影的节目单,方便大家使用下载。
2 node package
- fs
- cheerio
- superagent
- superagent-charset
- express
- 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 = [];
版权声明:本文标题:Node.js 抓取电影天堂新上电影节目单及ftp链接 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1727840474a1132920.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论