How to extract href value from html

There is a part of html code:

<table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td style="text-align:center;padding-bottom:42px;padding-top:12px" colspan="3"><a href="https://test.com/3e06cc40-f893-48c1-bf14-77668d1d8663"
                style="color:#fff;text-align:center;border-radius:32px;background-color:#007ce2;padding:14px 55px;line-height:30px;text-decoration:none;border:none;display:inline-block;font-size:16px">Accept
                invitation</a></td>
    </tr>
</table>

I need to extract only href value: https://test.com/3e06cc40-f893-48c1-bf14-77668d1d8663
But, I can’t write correct path to this element.

I tried like this:
var jsonData = pm.response.json();
var aa = jsonData.payload.parts[0].body.data
const $ = cheerio.load(atob(aa));
console.log($(“a[name=‘Accept invitation’]”).attr(‘href’));

Of course, my example doesn’t work.
How it is possible?

The following appears to work.

let html = `
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td style="text-align:center;padding-bottom:42px;padding-top:12px" colspan="3"><a href="https://test.com/3e06cc40-f893-48c1-bf14-77668d1d8663"
                    style="color:#fff;text-align:center;border-radius:32px;background-color:#007ce2;padding:14px 55px;line-height:30px;text-decoration:none;border:none;display:inline-block;font-size:16px">Accept
                    invitation</a></td>
        </tr>
    </table>`

const $ = cheerio.load(html);
console.log($('td').find('a').attr('href')) // https://test.com/3e06cc40-f893-48c1-bf14-77668d1d8663
1 Like

Thanks a lot, it wokrs! :slight_smile: