我一直试图运行我的phantomjs awslambda来获取一些网址的屏幕截图以供官方使用。它给出了一个错误,表明它无法在lambda中找到变量模块。到目前为止,我在本地Windows机器上运行了phantomjs代码。我将我的代码与phantomjs linux二进制打包在一起。任何帮助都将不胜感激。 这就是我编写代码的方式。
exports.myHandler = function(event, context) {
var url = "http://stackoverflow.com/posts/41711963/edit";
var Id = "c4f3b48d-469a-448a-8a8e-c5a09d1e79fd";
// var EncodedUri = "NB2HI4B2F4XXO53XFZZWKY3VOJUXI6LGN5RXK4ZOMNXW2L3CNFSC6NZXGIYTC===";
var pattern = /mp[3-4]$/;
if(pattern.test(url) == true){
console.log("Matched:");
var base64 = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCABkAGQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dX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8gAegr5Voo2E1fc/QD/h6fBLaFpfhzELvcMIt/IYsfic5615J8V/8Agob8RPiFp8+m6LBaeC9NnUrImnEvOwIwR5rDOPwz3BFfLVFW5yas2SoRTukPnnlup5JppHmmkYs8kjFmYnqST1NMooqCwooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//2Q==";
console.log(base64);
}
else{
var page = require('webpage').create();
page.viewportSize = {
width: 15,
height: 45
};
page.zoomFactor = 0.15;
page.open(url);
console.log("waiting for page to load...")
page.onLoadFinished = function(status) {
setTimeout(function(){
console.log('Status: ' + status);
var render = renderPageThumbNail(page);
},10000)
}
var renderPageThumbNail = function(page){
console.log("It will render the thumbnail of the url");
var base64 = page.renderBase64('png');
// var path = 'D:/MyProjectsWorkSpace/ScreenShots/output.txt';
console.log(base64);
phantom.exit();
}
}
}
它正在断行var page = require('网页')。create();