【问题标题】:Diffbot: "Where I can pass stats argument in analyze API?"Diffbot:“我可以在分析 API 中在哪里传递 stats 参数?”
【发布时间】:2014-10-20 07:36:06
【问题描述】:

我正在使用 Diffbot 分析 API 来检测页面类型,我想要类似的结果 这个

{"stats":{"times": {"docParseTime":0,"docGlobalsTime":0,"fetchAndRenderTime":586,"typeTime":0},"fromCache":true,"types":{"recipe":0,"discussion":0,"audio":0,"error":0,"location":0,"faq":0,"image":0,"job":0,"download":0,"game":0,"product":0,"frontpage":0,"document":1,"article":0,"event":0,"chart":0,"serp":0,"reviewslist":0,"video":0,"profile":0}},"request":{"pageUrl":"http://www.irs.gov/pub/irs-pdf/fw4.pdf","api":"analyze","version":3,"options":["stats"]},"type":"other","objects":[]}

但目前我越来越喜欢 这个

{"request":{"pageUrl":"http://static.nfl.com/static/content/public/image/rulebook/pdfs/2013%20-%20Rule%20Book.pdf","api":"analyze","version":3},"type":"other","objects":[]}

我必须在请求中传递“stats”参数。 但是在请求的地方,我可以传递这个论点。 谢谢,

【问题讨论】:

    标签: javascript node.js diffbot


    【解决方案1】:

    您好,我知道了,这是解决方案,只需自定义 Diffbot 库文件或在您的文件中写入由您决定,这里是代码

    var diffbot = new Diffbot('xxxxxxxxxxxxxxxxx');
    diffbot.analyze({
    uri: "http://www.visitcalifornia.in/media/pages/getting_around/maps/ORANGE-COUNTY.pdf",
    html: true,
    comments: true,
    stats: true
    }, function(err, response) {
    }
    

    这是自定义库代码

    Diffbot.prototype.analyze = function (options, callback) {
      for (var i in options) {
       this[i] = options[i];
      }
    
      var options = this;
      // support 'url'
      if (options.url) {
        options.uri = options.url;
        delete options.url;
      }
    
      if (!options.uri) {
        throw new Error("the URI is required.");
      }
    
      var diffbot_url = "http://api.diffbot.com/v3/analyze?token=" + this.token + "&url=" +  encodeURIComponent(options.uri)+"&fields=stats"; 
      if (options.stats) {
         diffbot_url += "&stats=1";
      }
    
      request({uri: diffbot_url}, function(error, response, body) {
         if (error) {
           callback(error, undefined);
         } else {
          callback(false, JSON.parse(body));
         }
      });
    }
    

    它就像魅力一样!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-23
      • 1970-01-01
      • 2016-09-22
      • 2018-04-25
      • 1970-01-01
      • 1970-01-01
      • 2016-09-17
      • 1970-01-01
      相关资源
      最近更新 更多