Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
snoopyxdy
committed
Jun 28, 2013
0 parents
commit b4164bc
Showing
12 changed files
with
289 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build | ||
.git | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.git | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# 网页抓取器,带发邮件 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
var jsdom = require("jsdom"); | ||
var async = require("async"); | ||
var fs = require('fs'); | ||
var log4js = require('log4js'); | ||
var request = require('request'); | ||
|
||
var send_mail = require('./mail.js'); | ||
var house_name_array = require('./read_txt.js'); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
var logger = log4js.getLogger('cheese'); | ||
var jquery = fs.readFileSync("./deps/jquery.1.7.1.js").toString(); | ||
|
||
|
||
|
||
var HOUSE_URL = 'http://www.szfcweb.com/szfcweb/DataSerach/CanSaleHouseSelectIndex.aspx' | ||
|
||
var get_count = function(){ | ||
|
||
|
||
logger.info("send start"); | ||
|
||
|
||
jsdom.env({ | ||
html:HOUSE_URL, | ||
src:[jquery], | ||
done:function (errors, window) { | ||
if(errors) return logger.error(errors); | ||
var jq = window.$; | ||
var href_array =[]; | ||
var result_array = []; | ||
|
||
var form_obj={} | ||
jq('#aspnetForm input').each(function(){ | ||
form_obj[jq(this).attr('name')] = jq(this).val(); | ||
}) | ||
|
||
//console.log(form_obj) | ||
|
||
//获得a标签的href数组 | ||
/* | ||
解析a标签的jquery代码 | ||
*/ | ||
var async_array = []; | ||
var reg = /共 \d+ 条/ | ||
|
||
house_name_array.forEach(function(v){ | ||
async_array.push(function(callback){ | ||
|
||
var obj = JSON.parse(JSON.stringify(form_obj)); | ||
obj["ctl00$MainContent$txt_Pro"] = v.name | ||
obj["ctl00$MainContent$ddl_houseclass"] = v.is_zz ? 'HC001' : 'HC002'; | ||
var r = request.post(HOUSE_URL,function(e,res,body){ | ||
if(e) return callback(e); | ||
var zz_r = reg.exec(body); | ||
if(zz_r){ | ||
zz_r = /\d+/.exec(zz_r[0]); | ||
result_array.push({ | ||
name:v.name, | ||
count:zz_r[0] | ||
}); | ||
|
||
} | ||
else{ | ||
result_array.push({ | ||
name:v.name, | ||
count:-1 | ||
}); | ||
} | ||
callback(); | ||
}).form(obj) | ||
|
||
}) | ||
}) | ||
|
||
|
||
async.series(async_array, | ||
// optional callback | ||
function(err, results){ | ||
if(err) return logger.error(err); | ||
var str = ""; | ||
result_array.forEach(function(v,i){ | ||
str += v.name +'\t'+v.count+'\n<br/>'; | ||
}) | ||
|
||
send_mail(str, function(err,response){ //去发送邮件 | ||
if(err) return logger.error(err); | ||
//console.log(response) | ||
logger.info("send end"); | ||
}) | ||
|
||
}); | ||
|
||
}//end done function | ||
|
||
});//end jsdom | ||
|
||
|
||
|
||
|
||
}; | ||
|
||
|
||
|
||
|
||
exports.loop_fn = get_count; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
逸庭 | ||
玲珑湾 | ||
独墅 | ||
海悦 | ||
熙岸 | ||
------------ | ||
东方之门大厦 | ||
万宝商业广场 | ||
乐嘉大厦 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[2013-06-29 01:02:13.145] [INFO] cheese - send start | ||
[2013-06-29 01:02:23.809] [INFO] cheese - send end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
var cluster = require('cluster'); | ||
var loop_fn = require('./dom.js').loop_fn; | ||
var log4js = require('log4js'); | ||
var loop_time = 1000*60*60*24; | ||
|
||
log4js.configure({ | ||
appenders: [ | ||
//{ type: 'console' }, | ||
{ type: 'file', filename: './logs/cheese.log', category: 'cheese' } | ||
] | ||
}); | ||
var logger = log4js.getLogger('cheese'); | ||
|
||
|
||
if (cluster.isMaster) { | ||
// Fork workers. | ||
|
||
cluster.fork(); | ||
|
||
|
||
cluster.on('exit', function(worker, code, signal) { | ||
logger.fatal('worker ' + worker.process.pid + ' died'); | ||
cluster.fork(); | ||
}); | ||
} else { | ||
loop_fn(); | ||
setInterval(function(){ | ||
loop_fn(); | ||
},loop_time) | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var tips = '选中复制的数字到excel,然后选中数字,选择 数据->分列,分隔符选择空格,下一步,搞定!!'; | ||
var accouont = 'loushenghai1981@hotmail.com'; | ||
var pwd = '123456lsh' | ||
var qq_acc = require('./qq_acc.json'); | ||
|
||
|
||
|
||
var nodemailer = require("nodemailer"); | ||
|
||
// create reusable transport method (opens pool of SMTP connections) | ||
var smtpTransport = nodemailer.createTransport("SMTP",{ | ||
service: "QQ", | ||
auth: { | ||
user: qq_acc.user, | ||
pass: qq_acc.pass | ||
} | ||
}); | ||
|
||
|
||
|
||
var send_mail = function(string,callback){ | ||
var string = string || ''; | ||
var callback = callback || function(){}; | ||
//console.log(string) | ||
|
||
// setup e-mail data with unicode symbols | ||
var mailOptions = { | ||
from: "loushenghai1981 ✔ <"+qq_acc.user+">", // sender address | ||
to: "655028@qq.com, 53822985@qq.com", // list of receivers | ||
subject: "szhouse ✔", // Subject line | ||
//text: string, // plaintext body | ||
html: string+"<br/><br/><br/><b>"+tips+" ✔</b>" // html body | ||
} | ||
|
||
// send mail with defined transport object | ||
smtpTransport.sendMail(mailOptions, function(error, response){ | ||
callback(error,response); | ||
smtpTransport.close(); | ||
// if you don't want to use this transport object anymore, uncomment following line | ||
//smtpTransport.close(); // shut down the connection pool, no more messages | ||
}); | ||
|
||
|
||
} | ||
|
||
|
||
module.exports = send_mail; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"author": { | ||
"name": "doublespout", | ||
"email": "snoopyxdy@163.com", | ||
"url": "http://snoopyxdy.blog.163.com" | ||
}, | ||
"name": "szhouse", | ||
"description": "szhouse reques", | ||
"keywords": [ | ||
"node", | ||
"szhouse" | ||
], | ||
"version": "0.1.0", | ||
"url": "https://github.com/DoubleSpout/szhouse", | ||
"homepage": "https://github.com/DoubleSpout/szhouse", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/DoubleSpout/szhouse.git" | ||
}, | ||
"main": "index.js", | ||
"engines": { | ||
"node":">=0.10.0" | ||
}, | ||
"dependencies":{ | ||
"jsdom":"0.6.5" | ||
}, | ||
"scripts": { | ||
"tset":"node ./test/main.js", | ||
"async":"0.2.9", | ||
"log4js":"0.6.6", | ||
"nodemailer":"0.4.4", | ||
"request":"2.21.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"user":"", | ||
"pass":"" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
String.prototype.trim= function(){ | ||
// 用正则表达式将前后空格 | ||
// 用空字符串替代。 | ||
return this.replace(/(^\s*)|(\s*$)/g, ""); | ||
} | ||
|
||
var pos_str = '---'; | ||
var fs = require('fs'); | ||
var txt_content = fs.readFileSync("./house.txt").toString(); | ||
var all_array = txt_content.split('\n').map(function(v,i){ | ||
if(~v.indexOf('--')) return pos_str | ||
return v.trim(); | ||
}) | ||
var pos = all_array.indexOf(pos_str); | ||
|
||
var zhu_zhai = all_array.slice(0,pos); | ||
var fei_zhu_zhai = all_array.slice(pos+1); | ||
|
||
var house_name_array = []; | ||
|
||
zhu_zhai.forEach(function(v){ | ||
house_name_array.push({ | ||
name:v, | ||
is_zz:1 | ||
}) | ||
}) | ||
|
||
fei_zhu_zhai.forEach(function(v){ | ||
house_name_array.push({ | ||
name:v, | ||
is_zz:0 | ||
}) | ||
}) | ||
|
||
|
||
module.exports = house_name_array; | ||
|