/*
使用request + cheerio来爬取zngirls网站上的数据
*/
const request = require('request');
const http = require('http');
const fs = require('fs');
const cheerio = require('cheerio');
const url = require('url');
const util = require('util');
const path = require('path');
const process = require('process');
const events = require('events');
const EventEmitter = events.EventEmitter;
const async = require('async');
function Crawl(girlID) {
this.girlID = girlID;
this.girlUrlFmt = 'http://www.zngirls.com/girl/%d/';
//同时可以执行两个
var self = this;
this.queue = async.queue(function (task, callback) {
//console.log('Hello' + task.name);
//执行操作
console.log('url:' + task.url + ' file:' + task.file);
self.download2(task.url, task.file, callback);
}, 2);
}
Crawl.prototype = {
start: function () {
//爬取个人主页
var self = this;
request.get(this.U(this.getGirlUrl()), function (err, response, body) {
if (err) {
console.error('错误信息:', err);
} else {
var $ = cheerio.load(body);
nodejs使用asyn优化的爬取
最新推荐文章于 2024-04-06 01:27:32 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)