Link Labels from Web Page

Hi All – a few weeks back, @JMichaelTX posted a javascript to pull links from a webpage (copied below) which worked so beautifully. I had begun the tedious process of breaking apart the full html text using Applescript when I came upon it and it was so much easier.

I’m wondering if anyone knows how I might either alter it slightly to return the link label(s) as well? (i.e., in
<a href="https://www.google.com/en-US/">Go to Google</a>
how would I reference the “Go to Google?” Or else a simpler way in Applescript that I simply haven’t been aware of.

Thank you so much!

(function myMain() {
var pdfElem = document.querySelectorAll('a[href*="pdf" i]')
var pdfList = Array.from(pdfElem).map(function(x) {return x.href;});
return pdfList.join("\n");
})();