# HTML response : Get data inside script tag

**URL:** <https://community.postman.com/t/html-response-get-data-inside-script-tag/20137>\
**Category:** Help Hub\
**Tags:** html-response, script-tag\
**Created:** [February 7, 2021, 1:34pm UTC](https://community.postman.com/t/html-response-get-data-inside-script-tag/20137 "2021-02-07T13:34:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sonutitus](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@sonutitus](https://community.postman.com/u/sonutitus)\
**Post date:** [February 7, 2021, 1:34pm UTC](https://community.postman.com/t/html-response-get-data-inside-script-tag/20137/1 "2021-02-07T13:34:01Z")

</div>

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”

 ![tempsnip](https://us1.discourse-cdn.com/getpostman/original/3X/d/a/dac40d6d6ddbd474d5f00f28714d76fc4c458aea.png)

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [February 8, 2021, 3:24am UTC](https://community.postman.com/t/html-response-get-data-inside-script-tag/20137/2 "2021-02-08T03:24:40Z")

</div>

@sonutitus Cheerio would be a good option here:

I saw a similar post [here.](https://community.postman.com/t/parse-html-form-response-data/2215) Kindly go though this to know more about cheerio 🙂

You can try the below snippet,

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

```auto
const $ = cheerio.load(responseBody);
//console.log($.html());

console.log($("script[windowRequestVerficationToken]").val());

```

---

<div class="post-metadata">

**Author:** ![sonutitus](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@sonutitus](https://community.postman.com/u/sonutitus)\
**Post date:** [February 9, 2021, 9:46am UTC](https://community.postman.com/t/html-response-get-data-inside-script-tag/20137/3 "2021-02-09T09:46:09Z")

</div>

> [@bpricilla](#):
>
> ```auto
> const $ = cheerio.load(responseBody);
> //console.log($.html());
> 
> console.log($("script[windowRequestVerficationToken]").val());
> 
> ```

Hi @bpricilla

Thank you for the reply 🙂

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">

<script>

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

</script>

<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>

```

---

<div class="post-metadata">

**Author:** ![sonutitus](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@sonutitus](https://community.postman.com/u/sonutitus)\
**Post date:** [February 9, 2021, 9:52am UTC](https://community.postman.com/t/html-response-get-data-inside-script-tag/20137/4 "2021-02-09T09:52:09Z")

</div>

@bpricilla  
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
    > 
    > );
```

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [February 9, 2021, 9:52am UTC](https://community.postman.com/t/html-response-get-data-inside-script-tag/20137/5 "2021-02-09T09:52:33Z")

</div>

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

```auto
const $ = cheerio.load(responseBody);
//console.log($.html());

console.log($("script[window.RequestVerificationToken]").val());

```

---

<div class="post-metadata">

**Author:** ![sonutitus](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@sonutitus](https://community.postman.com/u/sonutitus)\
**Post date:** [February 9, 2021, 9:54am UTC](https://community.postman.com/t/html-response-get-data-inside-script-tag/20137/6 "2021-02-09T09:54:32Z")

</div>

@bpricilla  
The above code is giving error  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/1/b1825af406fd1b10d5b01b056bf251871fb2f68c.png)
