流星 HTTP.call("get") 响应

Meteor HTTP.call("get") response

我正在尝试从各种网站中提取基本信息,例如标题和描述。我可以成功获得响应 object,而我得到的是整个网站 HTML。我一直在研究 HTTP.call 方法中的选项,但无法弄清楚如何仅 return 正是我想要从响应 object 中得到的。这是我要获取的两个元素:

<meta property="og:description" content="Our unique teaching style lets students develop their creative potential while learning solid computing skills.">

<meta property="og:site_name" content="Goldsmiths, University of London">

我可以通过搜索 <title></title> 的结果来轻松获得标题,但必须有更好的方法在调用方法选项中使用参数或数据。

Meteor.methods({
    getInfo: function (url) {
        HTTP.call('GET', url, {}, function (error, result) {
            if (!error) {
                //console.log(result);
                var titleStart = result.content.toLowerCase().indexOf('<title>'),
                    titleEnd = result.content.toLowerCase().indexOf('</title>'),
                    titleText = result.content.substring(titleStart + '<title>'.length, titleEnd)}

查看 meteor-scrape 包。

https://github.com/Anonyfox/meteor-scrape

以下是您如何使用它的示例:

# scrape any website
websiteData = Scrape.website "http://example.com/article"

结果:

{
  title: 'The Avengers (2012 film)'
  lang: 'en'
  descriptions: [ '2012 superhero film produced by Marvel Studios' ]
  tags: [ 'avengers' ]
  url: 'http://en.wikipedia.org/wiki/The_Avengers_(2012_film)'
  summary: '<p><i><b>Marvel\'s The Avengers</b></i> (classified under the name <i><b>Marvel Avengers Assemble</b></i> in the United Kingdom and Ireland), or simply <i><b>The Avengers</b></i>, is a 2012 American superhero film based on the Marvel Comics superhero team of the same name, produced by Marvel Studios and distributed by Walt Disney Studios Motion Pictures.<sup class="reference plainlinks nourlexpansion" id="ref_1">1</sup> It is the sixth installment in the Marvel Cinematic Universe. The film was written [...]'
  meta:
    caption: 'Theatrical release poster'
    director: '[Joss Whedon](http://en.wikipedia.org/wiki/Joss_Whedon)'
    producer: '[Kevin Feige](http://en.wikipedia.org/wiki/Kevin_Feige)'
    screenplay: 'Joss Whedon'
    based: '[The Avengers](http://en.wikipedia.org/wiki/Avengers_(comics))'
    music: '[Alan Silvestri](http://en.wikipedia.org/wiki/Alan_Silvestri)'
    cinematography: '[Seamus McGarvey](http://en.wikipedia.org/wiki/Seamus_McGarvey)'
    studio: '[Marvel Studios](http://en.wikipedia.org/wiki/Marvel_Studios)'
    runtime: '143 minutes'
    country: 'United States'
    language: 'English'
    budget: '0 million'
    gross: '.518 billion'
}