# How to extract href value from html

**URL:** <https://community.postman.com/t/how-to-extract-href-value-from-html/44592>\
**Category:** Help Hub\
**Created:** [March 1, 2023, 4:38pm UTC](https://community.postman.com/t/how-to-extract-href-value-from-html/44592 "2023-03-01T16:38:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aerospace-geologist3](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@aerospace-geologist3](https://community.postman.com/u/aerospace-geologist3)\
**Post date:** [March 1, 2023, 4:38pm UTC](https://community.postman.com/t/how-to-extract-href-value-from-html/44592/1 "2023-03-01T16:38:59Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [March 1, 2023, 5:48pm UTC](https://community.postman.com/t/how-to-extract-href-value-from-html/44592/2 "2023-03-01T17:48:30Z")

</div>

The following appears to work.

```auto
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

```

---

<div class="post-metadata">

**Author:** ![aerospace-geologist3](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@aerospace-geologist3](https://community.postman.com/u/aerospace-geologist3)\
**Post date:** [March 2, 2023, 12:05pm UTC](https://community.postman.com/t/how-to-extract-href-value-from-html/44592/3 "2023-03-02T12:05:25Z")

</div>

Thanks a lot, it wokrs! 🙂
