Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returns empty object? #21

Open
JulianKingman opened this issue Sep 12, 2015 · 3 comments
Open

Returns empty object? #21

JulianKingman opened this issue Sep 12, 2015 · 3 comments

Comments

@JulianKingman
Copy link

OK, so I'm probably doing something wrong here... I have a method that returns a scraped page, and am debugging it, this is what I have:

getContent: function(sourceLink){
    if(Meteor.isServer){
      console.log("getting source...", sourceLink);
      var webpage   = Scrape.website(sourceLink);
      console.log(webpage);
    }
  }

However, in the server console it's logging an empty object ( '{}' )
Why am I not getting the correct content? It makes no difference if I pass the link or put it in directly, it also doesn't matter what URL I use.

@repjackson
Copy link

Me too

@JulianKingman
Copy link
Author

@repjackson I ended up using the cheerio library. I installed meteorhacks:npm, added the cheerio library, and used the following:

var $ = cheerio.load(Meteor.http.get(url).content, {});
var parsed = $('body *').not('style, script').map(function(idx, el) { return $(el).text(); }).get();

May be more than you need, but it worked for me. It returns an array of text in tags on the page. To get just the html, you can do $('body').html() (I think).

@repjackson
Copy link

Impressive. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants