2016-01-22 41 views
1

我試圖從各種網站,如標題和說明拉基本信息。我可以成功獲取響應對象,而我得到的是整個網站的HTML。我一直在玩HTTP.call方法中的選項,但無法弄清楚如何僅從響應對象返回我想要的。這裏有兩個因素我想獲得:流星HTTP.call(「get」)迴應

<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>拿到冠軍很容易的,但必須使用PARAMS是一個更好的方法或呼叫方法選項中的數據。

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)} 

回答

1

查看流星刮包。

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: '$220 million' 
    gross: '$1.518 billion' 
}