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.

How to extract all the href links with submit link only

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Encompass Import System: Loans Processed</title>
<link rel="stylesheet" type="text/css" href="/Encompass/css-table.css">
<script type="text/javascript" src="/Encompass/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="/Encompass/Encompass.js"></script>
</head>
<body>
<table width="100%"><caption>Loans in process queue (Sorted by last modified)</caption>
<thead><tr>
<th scope="col">File Name</th>
<th scope="col">Loan Number</th>
<th scope="col">Date Created</th>
<th scope="col">Last Modified</th>
<th scope="col">Request</th>
</tr></thead><tbody>
<tr><td>FILECheckTestLoans.xlsx</td><td><a href=/LoanServicing/GetLoanData?loannumber=1000043845 target=loanDetail>1000043845</a></td><td>2021-03-04 15:37:49.437</td><td>2021-03-04 15:37:49.437</td><td><a href=/Encompass/RunUpdate?id=26088&requestId=1614893866191&ln=1000043845 target=_new>Submit</td></tr><tr><td>FILECheckTestLoans.xlsx</td><td><a href=/LoanServicing/GetLoanData?loannumber=1000043833 target=loanDetail>1000043833</a></td><td>2021-03-04 15:37:49.437</td><td>2021-03-04 15:37:49.437</td><td><a href=/Encompass/RunUpdate?id=26089&requestId=1614893866191&ln=1000043833 target=_new>Submit</td></tr><tr>