How can one parse HTML server-side with Meteor?

前端 未结 2 1670
不思量自难忘°
不思量自难忘° 2020-12-13 01:20

I want to be able to scrape links out of an HTML page that I am fetching with the Meteor.http method. Would be ideal to use jQuery on the server-side but I don\'t think this

2条回答
  •  星月不相逢
    2020-12-13 01:47

    Use cheerio, as Akshat suggests, but I would recommend a different way of using it, as of now, for Meteor 0.8.0.

    First, install npm for Meteor:

    $ mrt add npm
    

    Then modify packages.json to (of course you can have different version of cheerio, or other node packages as well):

    {
      "cheerio": "0.15.0"
    }
    

    In server.js (or any other file, in server-side code) start:

    var cheerio =  Meteor.require('cheerio');
    

    The use cheerio in a way you like.

    Upon running $ meteor it will automatically install cheerio.

提交回复
热议问题