Executing scripts on page

111 views
Skip to first unread message

pedro.f...@unparallel.pt

unread,
Nov 21, 2018, 7:00:32 AM11/21/18
to jsdom
Hello,

I'm looking for something that can read a webpage in javascript but without a browser, so I found JSDOM.
I was trying to get information from a website using this example:

const jsdom = require("jsdom");
const { JSDOM } = jsdom;

JSDOM.fromURL("https://www.abola.pt").then(dom => {
  console.log(dom.serialize())
});

But when I save the result in html and opened it with any browser, the page wasn't fully loaded. So I think may be it's need to execute some script to add a delay time to load page.
I read this (https://github.com/jsdom/jsdom#executing-scripts) but I don't know how to execute javascript in my code.
I also read this (https://stackoverflow.com/questions/10185903/jsdom-doesnt-process-script-inside-web-page) but it seems that is for JSDOM older versions.

Please can you give me some advice or solution?
Thanks.

Best regards,
Pedro Ferreira
teste.html

pedro.f...@unparallel.pt

unread,
Nov 22, 2018, 10:07:58 AM11/22/18
to jsdom
I changed my code to:


const jsdom = require("jsdom");
const { JSDOM } = jsdom;

var options = {
     resources: "usable",
     runScripts: "dangerously"
 };

JSDOM.fromURL("https://www.abola.pt", options).then(result => {
  console.log(result.serialize())
});


But it seems that page's javascript isn't executed yet
Reply all
Reply to author
Forward
0 new messages