HTML response : Get data inside script tag

Hi Team,

It would be life saver if someone could help, with the getting the value inside the script tag as seen from the below image?.. attribute named “window.RequestVerificationToken”

@sonutitus Cheerio would be a good option here:

I saw a similar post here. Kindly go though this to know more about cheerio :slight_smile:

You can try the below snippet,

I just worked roughly since only the snapshot of the response in provided.

const $ = cheerio.load(responseBody);

1 Like

Hi @bpricilla

Thank you for the reply :slight_smile:

I couldn’t fetch the value using the above resolution, so I am sharing the html response.

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta author="Test data">

<meta name="description" content="Test Admin Platform">

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="icon" id="favicon" type="image/x-icon" href="/favicon.ashx?random=09412021">


    window.RequestVerificationToken = 'CBnB25ZY1CVQL4ReM0qzAs_StmlUd2W2FDlG_jOnEuz4M5_3eKZ0xjlfxQdDMlUqVyCaFwYkFadOZauk1GMgwXsam8z5sH-vcxXuq4OF-Os1:jRpBEiVZHiSw7uZQ8J3gCrUPOQB7DdWEcRROiQ38izHsEgeKXNjmaS6WFAqwEcvPKwEvvAvwly5T4T6p3x_7_N1KmltGZBEVlP3FDEdr7ODdKidgPwgXVWERKZco4eWV0';


<title> QA - Dashboard </title>

<link href="/admin/Content/css?v=m-g1hzBEAwRLe9AfwA4CizfS_1A1AB4GcXnTUjKDCIU1" rel="stylesheet" />

<link href="/admin/FreeTrial/Tour?v=jkAKiMEku7GE0j6LMaS8Qa6jpTUyyrXbhoKKWIh-yKI1" rel="stylesheet" />

<script src="/admin/bundles/modernizr?v=inCVuEFe6J4Q07A0AcRsbJic_UE5MwpRMNGcOtk94TE1"></script>

I am presently using the below code, but this would fail if the script tag is changing length.

    > **const** $ = cheerio.load(pm.response.text());
    > var str=$('script')[0].children[0].data
    > //console.log(str)
    > var mySubString = str.substring(
    >     str.lastIndexOf("= '") +3 , 
    >     str.lastIndexOf(";") -1
    > );

Thaks for sharing it, but before that. I missed a minute detail. can you try as below

const $ = cheerio.load(responseBody);


The above code is giving error