Forum Moderators: open

Message Too Old, No Replies

Asp script

         

stevelibby

4:40 pm on Sep 15, 2006 (gmt 0)

10+ Year Member



how can i retrieve the meta tags from a site using asp?

mrMister

6:06 pm on Sep 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Grab the page using the MS HTTPRequest object and parse the result with a regular expression.

stevelibby

8:10 pm on Sep 15, 2006 (gmt 0)

10+ Year Member



Hi
Thanks for replying.
where can i find information on this? i want to be able to extract title, description, keywords and the body if possible so i acn analyse the data.

mrMister

3:07 am on Sep 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use the following function to grab a remote document. Pass it a URL as a string and it'll return the HTML source as a string eg:

Dim htmlSource = getHtml("http://www.google.com/")

function getHTML (strUrl)
Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlHttp.Open "GET", strUrl, False
xmlHttp.setRequestHeader "User-Agent", "ASP HttpRequest"
xmlHttp.setRequestHeader "content-type", "application/x-www-form-urlencoded"
xmlHttp.Send
getHTML = xmlHttp.responseText
xmlHttp.abort()
set xmlHttp = Nothing
end function

Off the top of my head, your regular expression should be something like this...

.*meta name="description" content="(.+?)"

You can find how to use Regular Expressions on Google. The above regex might need refinement depending on your needs.