Skip to content

Instantly share code, notes, and snippets.

@xbklairith
Last active September 24, 2016 15:55
Show Gist options
  • Save xbklairith/87b2a6909672b1dbb01e0c24ef095ff7 to your computer and use it in GitHub Desktop.
Save xbklairith/87b2a6909672b1dbb01e0c24ef095ff7 to your computer and use it in GitHub Desktop.
var cheerio = require('cheerio');
var request = require('request')
var prettyjson = require('prettyjson')
function gotHTML(err, resp, html) {
if (err) return console.error(err)
var parser = cheerio.load(html)
topic = {}
topic.title = parser('h2').text()
topic.story = parser('.display-post-story', '.main-post').text()
console.log(prettyjson.render(topic))
var options = {
url: 'http://pantip.com/forum/topic/render_comments?tid=35614484',
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36',
'accept': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
}
};
request(options, function(err, resp, html) {
// console.log(prettyjson.render(resp.body))
console.log(prettyjson.render(JSON.parse(resp.body).comments.length));
console.log(prettyjson.render(JSON.parse(resp.body).comments[0].message));
// console.log(prettyjson.render(JSON.parse(resp.body).comments[0].emotion));
// console.log(prettyjson.render(JSON.parse(resp.body).comments[0].good_bad_vote));
})
}
req = request('http://pantip.com/topic/35614484', gotHTML)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment