Getting a specific content in HTML response

Hi @nguyenvietdungqsq

Welcome to the community! :clap:

In addition you can use cheero.js to load the HTML, and parse your results.

const response = cheerio.load(pm.response.text(), {
    ignoreWhitespace: true,
    xmlMode: true
});

const sessionId = response('script').find('sessionId')

The above may not working exactly, as I am shooting from the hip, but you can use cheerio to parse through your html and get to your element and then parse out the js from there.

However, I will have to agree with @allenheltondev, and having a sessionID in the js script of a html page is not good practice, and a bit unsafe. That information is better sent in headers or a JWT. I am no professional with communicating session IDs with web pages, however, from my experience, seeing it in the script portion of an html page is uncommon for me.

Hope this helps!

3 Likes