【问题标题】:AWS Lambda- get html of the websiteAWS Lambda - 获取网站的 html
【发布时间】:2017-06-12 15:45:45
【问题描述】:

我正在尝试在 AWS Lambda 中创建函数,该函数返回给定网站的 html。那是我的代码:

console.log('Loading function');

exports.handler = (event, context, callback) => {

var util = require("util"),
http = require("http");

var options = {
    host: "www.nyuad.nyu.edu/en/news-events/abu-dhabi-events.html",
    port: 80,
    path: "/"
};

var content = "";   

var req = http.request(options, function(res) {
    res.setEncoding("utf8");
    res.on("data", function (chunk) {
        content += chunk;
    });

    res.on("end", function () {
        util.log(content);
        callback(null, content);
    });
});

req.end();
};

它非常适合 'www.google.com' 作为 options 中的 host 参数,但是当我尝试更复杂时,类似于代码中的给定参数,我得到一个错误:

Error: getaddrinfo ENOTFOUND www.nyuad.nyu.edu/en/news-events/abu-dhabi-events.html www.nyuad.nyu.edu/en/news-events/abu-dhabi-events.html:80

at errnoException (dns.js:26:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)

【问题讨论】:

    标签: node.js amazon-web-services aws-lambda


    【解决方案1】:

    如果您查看http module 的文档,您会看到:

    • host:发出请求的服务器的域名或IP地址
    • path:请求路径,默认为'/'。如果有的话,应该包括查询字符串。例如。 '/index.html?page=12'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多