Getting HTML response - want to parse certain fields to next request

Please, let me know how to parse some fields from HTML response to next request.
Similar to this command for JSON response

var data = JSON.parse(responseBody);
postman.setEnvironmentVariable("id", data.id);

I’m trying to get fields by id from

<!DOCTYPE html>
<html>
............

    <input type="hidden" name="ID1" id="ID1" value="dfbldbldb" />
    <input type="hidden" name="templateID" id="templateID" value="sdfjsbh skjd" />
    <input type="hidden" name="ID2" id="ID2" value="sfsighs87y" />
    <input type="hidden" name="templateName" id="templateName" value="template name here" />

............
</html>

Hey @yglprn. The Postman Sandbox has cheerio as one of the supported libraries which you can use to parse HTML responses. Here’s what your use case might look like.

var html = cheerio(responseBody),
 id1 = html.find('#ID1').attr('value'),
 templateId = html.find('#templateID').attr('value'),
 id2 = html.find('#ID2').attr('value'),
 templateName = html.find('#templateName').attr('value');
 
console.log(id1, templateId, id2, templateName);
/*
dfbldbldb
sdfjsbh skjd
sfsighs87y
template name here
*/

You can update the value specified in.attr() as per your needs. Feel free to reach out if you have additional queries.

1 Like

Still i am unable to extract a value : Please help me further in detail

My Response in HTML is

4YbyKvmfRN-iR4Wjxv5YNXctxELXDO2V6C_SGfvLUwggTSQaqYeLlK1dV-YutnjecMbC0DRb6i9mi2YK8-ZdDMvikgn28HoSjifrPuTUMY6UwAkTRpU3dIz4-XPcg4krLe_8cFvttD9wx6EfHM8fGtsW7OxTlNRErJ5-o9FjoGC_E_pqwEZb3v6yMzOMWM0L3ZbWL284WYYALuhtfkB6rQ==

surya.ponnusamy_egov
What are you trying to extract?

Hi Thanks for the reply. I am extracting a token value which lies between HTML tag

and also there are plenty of attributes in the table. This is why i am unable to extract the particular token value.