View Full Version : Getting Links from an external page?

03-14-2007, 06:21 PM

My main question is can i read the HTML source from one page in to a varible? If any one has any ideas on how to produce similar asp code to that featured on the link would be great. Any Help Much Appreciated.:thumbsup:

03-14-2007, 10:11 PM
You could do a screen scrape and get the data using the XMLHTTP object. This would put all of the html into a variable. You will now have to manipulate that variable to get the exact data that you are looking for

Something like this

Dim xml
Dim page
Dim LinkStart
Dim LinkEnd
Dim hyperLink
Dim intCurrent
Dim intUsed
' Create an xmlhttp object:
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
' Opens the connection to the server.
xml.Open "GET", "http://www.somewebsite.com/", False
' Actually Sends the request and returns the data:
'fills the variable
page = xml.responseText
Set xml = Nothing 'removes the object from server memory
'now all this is left is to parse the variable to get the links out of it
LinkStart = "<a "
LinkEnd = "</a>"

Do until y = true
If InStr(1,page,LinkStart) <> 0 Then 'ensure there is a link to grab from the page
intCurrent = Len(page)
intUsed = InStr(1,page,LinkEnd)+4
If (InStr(1,page,LinkStart)) < intUsed Then
hyperLink = mid(page, InStr(1,page,LinkStart), intUsed - InStr(1,page,LinkStart)) & "<br>"
page = Right(page, (intCurrent-intUsed))
Else 'just in case someone has placed an inadvertant </a> in the page
page = Right(page, (intCurrent-intUsed))
End If
Response.Write hyperLink & "<br>" & vbCrLF
y = true
End If

03-15-2007, 01:35 PM
I have read your both the threads.
You can do this by javascript.

Visit this:
This software helps you..

04-18-2007, 04:52 PM
You can do this by javascript.
javascript cannot access external domains.

Visit this:
This software helps you..
That is nothing to do with ASP

With ASP, to grab the page you need xmlHTTP as mentioned above.

To extract HTML you can use Regular Expressions