Parse HTML form response data and extract form attributes

I have a form in response like blow code. I want to get “action” and “method” using cheerio lib. How can I do that?

<form action="https://my.url.com" method="post">
    .....
    <input type="submit" value="Submit" />
</form>
const $ = cheerio.load(responseBody);

const $form = $('form');
const action = $form.attr('action');
const method = $form.attr('method');

Here’s a link to the cheerio website which includes more advanced examples should you need them:

2 Likes

Okay, I found it this way:
console.log($( ‘form’ ).attr(‘action’));

error
@hesam.kamalan @matt

lets say url is /appstest/RunUpdate?id=26216&requestId=1614895894455&ln=1000043845 want to print id, requestId, ln values only in console

How to extract all the href links with submit linknames from below html response

<!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>appstest Import System: Loans Processed</title>
<link rel="stylesheet" type="text/css" href="/appstest/css-table.css">
<script type="text/javascript" src="/appstest/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="/appstest/appstest.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=/appstest/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=/appstest/RunUpdate?id=26089&requestId=1614893866191&ln=1000043833 target=_new>Submit</td></tr><tr><td>FILECheckTestLoans.xlsx</td><td><a href=/LoanServicing/GetLoanData?loannumber=1000043832 target=loanDetail>1000043832</a></td><td>2021-03-04 15:37:49.437</td><td>2021-03-04 15:37:49.437</td><td><a href=/appstest/RunUpdate?id=26090&requestId=1614893866191&ln=1000043832 target=_new>Submit</td></tr><tr><td>FILECheckTestLoans.xlsx</td><td><a href=/LoanServicing/GetLoanData?loannumber=1000043831 target=loanDetail>1000043831</a></td><td>2021-03-04 15:37:49.437</td><td>2021-03-04 15:37:49.437</td><td><a href=/appstest/RunUpdate?id=26091&requestId=1614893866191&ln=1000043831 target=_new>Submit</td></tr><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=/appstest/RunUpdate?id=26092&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=/appstest/RunUpdate?id=26093&requestId=1614893866191&ln=1000043833 target=_new>Submit</td></tr><tr><td>FILECheckTestLoans.xlsx</td><td><a href=/LoanServicing/GetLoanData?loannumber=1000043832 target=loanDetail>1000043832</a></td><td>2021-03-04 15:37:49.437</td><td>2021-03-04 15:37:49.437</td><td><a href=/appstest/RunUpdate?id=26094&requestId=1614893866191&ln=1000043832 target=_new>Submit</td></tr><tr><td>FILECheckTestLoans.xlsx</td><td><a href=/LoanServicing/GetLoanData?loannumber=1000043831