Score:0

Getting output of a javascript that was executed while loading webpage using phatomjs

in flag
Cas

When loading a web page, javascripts are executed to provide info. I want to "load" a page (including executing the javascripts), but instead of getting the html output after that, I want to get the output of one of the executed javascripts. I have the path to the webpage and the script.

This is exactly the same as going to google, loading a page while having dev-tools->console open and viewing a javascript and it's json output. I have the url of the site (e.g. https://example.com) and the url to the javascript I want to output of (e.g. https://example.com/script.js).

If it's possible, I would like to immediatly integrate jq to get the desired value in that json output as the output of the script (so the output of the script should just be the "raw" value of a key in the json output of that javascript).

And I prefer it being done using PhantomJS, however I'm open to other things.

  • I need to give the url via an argument. Inside the phantomjs script, the url would be $1 and the script url $1/script.js, to say it in bash language.
  • The jq "path" (aka .path.to.key) can be set in the script, so that doesn't need to be given via an argument.
  • I need to get the output in a variable of a bash script.

So those three points combined would be value=$(phantomjs test.js https://example.com)

Hopefully you can help me. Thanks!

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.