问题
I have an Azure website that has uses a thirty party script (DHTMLX Schedule library). I want to be able to render out a PDF and send it as an email as a weekly automated task.
I have a C# MVC page that is using their .NET Scheduler to render the schedule and at the moment, when the page loads in a browser it essentially does everything I need. However I am trying to create this as a scheduled task in Azure. The page has a lot of JavaScript and CSS which renders out the schedule which gets posted to their online service and creates a PDF.. because I am using a third party (and I have asked them) it's not really possible to extract this functionality out .. the PDF generator needs the styling and layout, etc.
I tried to hit the page using Azure jobs but there is obviously JavaScript on the page that can't run in their sandbox. So I turned to Node and JSDOM.
I've got a very basic node app.js running on my Azure instance and it runs the page (basically I get an email with the PDF link) however it only renders the very first elements of the page and so the PDF has barely any content.
I've included the code here from my app.js .. any pointers would be much appreciated. Thanks! By the way, I asked what was my best approach in this question I hope this is a valid case for a new question...?
var jsdom = require("jsdom");
jsdom.env({
url: "http:mywebsite.azurewebsites.net/Admin/scheduler?userid=89",
scripts: ["http://code.jquery.com/jquery.js"],
features: {
FetchExternalResources : ['script'],
ProcessExternalResources : ['script'],
},
done: function(err, window) {
if(!err){
console.log("done");
} else {
console.log("not done!");
}
}
});
回答1:
So I decided to use Selenium instead as I was just going round in circles with jsdom. I have a server to sit it on and it's working so no need for Node in this instance..
来源:https://stackoverflow.com/questions/35056467/azure-and-node-js-and-jsdom-scheduled-task-opening-a-webpage-with-scripts