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’));