美文网首页
node 爬虫

node 爬虫

作者: shadow123 | 来源:发表于2019-08-03 15:11 被阅读0次
const request = require('request');
const cheerio = require("cheerio");
const iconv = require('iconv-lite')

let url = 'http://m.17dm.com/wugengji/manhua/124112.html'
request(url,function (error, response, body) {
    if(response && response.statusCode == 200){
        var html = iconv.decode(body.toString(),'gb2312');
        var $ = cheerio.load(html)
    }
    
    console.log($('select[name="listNarImg"]').children("option:last-child").attr("value"))
});

// http://img.17dm.com/wugengji/manhua/2b21/17.jpg

const request = require('request');
const fs= require('fs')
let page = 8;
let setion = 21
let chapter = 2

async function downloadImage() {
    let url = `http://img.17dm.com/wugengji/manhua/${chapter}b${setion}/${page}.jpg`;
    if (!fs.existsSync(`wugeng/${chapter}`)) {//查看是否存在这个文件夹
        fs.mkdirSync(`wugeng/${chapter}`);
    }

    if (!fs.existsSync(`wugeng/${chapter}/${setion}`)) {//查看是否存在这个文件夹
        fs.mkdirSync(`wugeng/${chapter}/${setion}`);//不存在就建文件夹
        console.log(`wugeng/${chapter}/${setion} 文件夹创建成功`);
    } else {
        console.log(`wugeng/${chapter}/${setion} 文件夹已经存在`);
        
    }

    let headers ={
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36',
        'Connection':'keep-alive'
    };

    await request({
        url: url,
        encoding: 'binary'
    },function (error, response, body) {
        if (!error && response.statusCode == 200) {
            console.log('开始下载')
            if(!body)  console.log("(╥╯^╰╥)哎呀没有内容。。。")
            fs.writeFile(`wugeng/${chapter}/${setion}/${page}.jpg`,body, 'binary', function (err) {
                if (err) {console.log(err);}
                console.log(`wugeng/${chapter}/${setion}/${page}.jpg 下载成功`);
        
            })
        }

        setTimeout(()=>{
            page++
            if(page == 34){
                setion++ 
                page = 1
            }
            if(setion == 64){
                chapter = 3
                setion = 1;
                page = 1
            }
            downloadImage()
        },300)
    })
}

downloadImage()

相关文章

  • node爬虫之路(一)

    最近对爬虫很感兴趣,我们node.js也是可以写爬虫。所以写一个node爬虫系列,记录我的爬虫之路,感兴趣的同学可...

  • node爬虫快速入门

    node爬虫 初入前端,刚刚接触node,对于耳闻已久的node爬虫非常神往,所以有了这篇文章,项目代码在文章末尾...

  • node入门场景之——爬虫

    边做边学效率更高,爬虫是node的适用场景之一,关于爬虫的另一篇文章node爬虫进阶之——登录为了验证“经验总结、...

  • node 爬虫

    clawer.js

  • node爬虫

    node爬虫用到的第三方模块 Cheerio 服务端的jQueryhttps://segmentfault.c...

  • Node爬虫

    使用cheerio爬虫模块抓取页面后获取元素信息跟jQuery基本一样

  • node爬虫

    /** 教程:https://blog.csdn.net/Qc1998/article/details/83154...

  • node 爬虫

  • node爬虫

    声明:所有文章都是转载整理的,只是为了自己学习,方便自己观看,如有侵权,请立即联系我,谢谢~ Node.js的学习...

  • node爬虫

    以下代码爬取豆瓣电影网的数据并且写入数据库首先安装cheerio和mysql

网友评论

      本文标题:node 爬虫

      本文链接:https://www.haomeiwen.com/subject/ipmjdctx.html