Created
May 17, 2014 18:59
-
-
Save kpman/e19ef436a8873dc4cdc9 to your computer and use it in GitHub Desktop.
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
var request = require('request'); | |
var cheerio = require('cheerio'); | |
request('http://thehackernews.com/', function(error, response, html) { | |
if (!error && response.statusCode == 200) { | |
var $ = cheerio.load(html); | |
var parseResult = []; | |
$(".post").each(function(i, element) { | |
var title = $(this).find("h1").text(); | |
var date = $(this).find("span.dtstamp.author").attr("title"); | |
var like = $(this).find("span.pluginCountTextDisconnected").html(); | |
var digest = $(this).find(".post-body div div").text().split("."); | |
var first_digest = digest[0] + "."; | |
var postInfo = { | |
title: title, | |
date: date, | |
like: like, | |
digest: first_digest | |
} | |
parseResult.push(postInfo); | |
}); | |
console.log(parseResult); | |
} else { | |
console.log("there are some error"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment