http - meteor HTTP.call ("get") 响应

标签 http meteor call response

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

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

关于http - meteor HTTP.call ("get") 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34937700/

相关文章:

android - 可以使用 MQTT 来实现请求/响应行为吗

c - 如何在c中发送登录POST/GET请求并接收响应

javascript - mailto 不适用于大正文内容

c++ - 使用程序作为包含主要功能的库

java - 将特定的 cUrl 请求转换为 Java/使用 Java

java - 如何使用 Java 从相对 URL 构建绝对 URL?

meteor - 可以从控制台找到所有客户端集合吗?

javascript - angularjs ui-router 解析不是不安全吗?

c++ - 在 Lua 中调用 tolua++ 中可能未公开的函数

python - 为多个类创建调用函数