Home >php教程 >php手册 > Node.js批量抓取高清妹子图片

Node.js批量抓取高清妹子图片

WBOY
WBOYOriginal
2016-06-07 11:39:521434browse

妹子不错,统统抓起来!
http://www.focalhot.com/blog/62.html
//依赖模块<br> var fs = require('fs');<br> var request = require("request");<br> var cheerio = require("cheerio");<br> var mkdirp = require('mkdirp');<br>  <br> //目标网址<br> var url = 'http://me2-sex.lofter.com/tag/美女摄影?page=';<br>  <br> //本地存储目录<br> var dir = './images';<br>  <br> //创建目录<br> mkdirp(dir, function(err) {<br>     if(err){<br>         console.log(err);<br>     }<br> });<br>  <br> //发送请求<br> request(url, function(error, response, body) {<br>     if(!error && response.statusCode == 200) {<br>         var $ = cheerio.load(body);<br>         $('.img img').each(function() {<br>             var src = $(this).attr('src');<br>             console.log('正在下载' + src);<br>             download(src, dir, Math.floor(Math.random()*100000) + src.substr(-4,4));<br>             console.log('下载完成');<br>         });<br>     }<br> });<br>  <br> //下载方法<br> var download = function(url, dir, filename){<br>     request.head(url, function(err, res, body){<br>         request(url).pipe(fs.createWriteStream(dir + "/" + filename));<br>     });<br> };

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn