Node.js Saving a GET request's HTML response -


i'm apparently little newer javascript i'd care admit. i'm trying pull webpage using node.js , save contents variable, can parse feel like.

in python, this:

from bs4 import beautifulsoup # parsing import urllib text = urllib.urlopen("http://www.myawesomepage.com/").read() parse_my_awesome_html(text) 

how in node? i've gotten far as:

var request = require("request"); request("http://www.myawesomepage.com/", function (error, response, body) { /* here lets me access text outside of closure doesn't work: this.text = body; */ }) 

var request = require("request"); var parsemyawesomehtml = function(html) { //have @ }; request("http://www.myawesomepage.com/", function (error, response, body) { if (!error) { parsemyawesomehtml(body); } else { console.log(error); } }); 

edit: kishore noted, there nice options parsing available. see cheerio if have python/gyp issues jsdom on windows. cheerio on github


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -