Answers for "javascript extract links from webpage string"

-1

javascript extract links from webpage string

var rawHTML = '<html><body><a href="foo">bar</a><a href="narf">zort</a></body></html>';

var doc = document.createElement("html");
doc.innerHTML = rawHTML;
var links = doc.getElementsByTagName("a")
var urls = [];

for (var i=0; i<links.length; i++) {
    urls.push(links[i].getAttribute("href"));
}
alert(urls)
Posted by: Guest on December-05-2020

Code answers related to "javascript extract links from webpage string"

Code answers related to "Javascript"

Browse Popular Code Answers by Language