Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract hyperlinks from a webpage

Status
Not open for further replies.

llamatron

MIS
Aug 29, 2003
10
GB
Is it possible to extract all the hyperlinks in an external webpage I open in a popup using Javascript and store them in a variable so that the string can be manipulated or is there a security issue with this too?
 
not possible due to security restrictions: js will not allow you to read properties of a window that is outside your domain.


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
I know it's not what you asked... but... it can be done with ASP. Just a thought.
 
It can be done using client side script, but you need to use the MSXML Http Request object (IE only).

Code:
<html>
<head>
<script>
function getLinks(){
 var httpReq = new ActiveXObject(&quot;MSXML2.XMLHTTP&quot;);
 httpReq.open(&quot;Get&quot;, &quot;[URL unfurl="true"]http://www.yahoo.com&quot;,[/URL] false);
 httpReq.send();
 var newObj = document.createElement('div');
 newObj.innerHTML = httpReq.responseText;
 var links = newObj.getElementsByTagName('a');
 var resultStr = '';
 for(var i = 0; i < links.length; i++){
  resultStr = resultStr + links[i].href + '<br />';
 }
 document.getElementById('Results').innerHTML = resultStr;
}
</script>
</head>

<body onload=&quot;getLinks();&quot;>
<div id=&quot;Results&quot;></div>
</body>
</html>
 
That code above was awesome. I used it above to connect to a Lotus Notes view to genenerate a new layout of the data. But since JavaScript is excecuted on the client side, it takes a long time.

How can I do this in ASP/VBScript?

I am stuck on what the eqivalent of var newObj = document.createElement('div'); is in ASP.

Dim httpReq
Dim newObj

Set httpReq = Server.CreateObject(&quot;MSXML2.XMLhttp&quot;)httpReq.open &quot;Get&quot;, &quot;somepage.html&quot;, false
httpReq.send

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top