Skip to content

How can i extract a value of a script variable from another website’s source code

Lets just say I am beginner here.

I have this script on one website::

    var data;
    var sn = "429d-d51aa-c2ec-df694-6a3gc";
    var videoPlayer;
    var ea = "";

and the exact same piece of code on another website/URL’s source code. I want to reference the value of variable sn and ShowCh value (the long alphanumeric string) in my code from the other website’s updating values. Sorry for my layman language and poor english


Since the other site almost certainly has CORS restrictions on it, you’ll have to bounce the request off your own server.

When your site loads, make a request to your backend. Have the backend do something like:

const fetch = require('node-fetch');
  .then(res => res.text())
  .then((result) => {
    const sn = result.match(/ sn = "([^"]+)"/)[1];
    const chParam = result.match(/showCh*"(w+)/)[1];
    // Values retrieved; now send sn and chParam to client

Then your website’s frontend can take the response from your server and populate the variables appropriately.