参考堆栈溢出问题:
我想在Node.js中完成类似的任务,以便在我提供网址时获取网站信息:图像和名称。
我知道节点中的HEAD请求,但它不会提取该信息,而是返回HTML标头。
我该怎么办?
示例可以是当我们在Slack中发送一个url作为消息时,它会拉动Image和meta并自动显示。
通过一项小型研究,我最终提出了这样的请求:
var request = require('request');
request("http://stackoverflow.com", {method: 'HEAD'}, function (err, r es, body){
console.log(res.headers);
});
并获得基本标题信息:
{"cache-control":"private","content-length":"245925","content-type":"text/html; charset=utf-8","x-frame-options":"SAMEORIGIN","x-request-guid":"02d28d15-13e3-4d2e-8495-fa0ff5922224","accept-ranges":"bytes","date":"Mon, 06 Mar 2017 14:44:52 GMT","via":"1.1 varnish","connection":"close","x-served-by":"cache-lcy1130-LCY","x-cache":"MISS","x-cache-hits":"0","x-timer":"S1488811492.680621,VS0,VE89","x-dns-prefetch-control":"off","set-cookie":["prov=fbdc85f1-c72a-bcc4-8538-2572d0580c74; domain=.stackoverflow.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly"]}
但它没有我正在要求的图像和名称信息。