0

Let's say, when we open link https://example.com and that page generates javascript variable, called xyz, so we can access it from browser's Inspect console:

console.log(xyz);

However, how can we get & read that variable from node.js ? (the external link needs to be rendered like in browser, to get javascript values out of it).

T.Todua
  • 53,146
  • 19
  • 236
  • 237
  • There is [10 years old topic on SO](https://stackoverflow.com/questions/5222469/how-to-execute-htmljavascript-page-with-node-js), but I doubt it is applicable now and there should have changed many things in the meantime. – T.Todua Feb 21 '21 at 16:13

2 Answers2

1

There are different approaches to get the variable, depending how they are created.

  • variable is directly in source code so you can simply parse it using regEx for example.
  • variable is being evaluated in JS runtime, in this case you need to mock the browser environment using PhantomJS, which is quite heavy.
natchkebiailia
  • 611
  • 4
  • 18
  • yes, i have been talking about runtime evaluation. so, PhantomJS or Nightwatch seems possible route.. – T.Todua Mar 13 '21 at 17:39
0

One possible way seems to use plugin like Nightwatch. However, in the past it depended selenium, which is a bit heavy.

T.Todua
  • 53,146
  • 19
  • 236
  • 237