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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse HTML in variable and isolate <a href=...

Status
Not open for further replies.

bang99

Technical User
Feb 28, 2007
6
US
Hi,

I have basic html in a variable and I would like to find and put into a different variable the URL from each
Code:
<a href="[URL unfurl="true"]http://www.mysite.com/hello.asp?story=123">something</a>[/URL]
.

Each page will have a different number of anchor tags so i need to use an array that i can then put the items of the array into text fields of a form.

For example if the variable contains:
Code:
<html>
<head>
<title>Hello</title>
</head>
<body>
<a href="[URL unfurl="true"]http://www.yahoo.com">SomeSite01</a>Some[/URL] text la la la
<a href="[URL unfurl="true"]http://www.microsoft.com">SomeSite02</a>[/URL]
This is some more filler text.
<a href="[URL unfurl="true"]http://www.google.com">SomeSite03</a>[/URL]
</body>
</html>

The array items would contain theses results:
Code:
arrLinks(0) = "[URL unfurl="true"]http://www.yahoo.com"[/URL]
arrLinks(1) = "[URL unfurl="true"]http://www.microsoft.com"[/URL]
arrLinks(2) = "[URL unfurl="true"]http://www.google.com"[/URL]

I have been working on this for many hours and I'm not getting how to do it.

Thank you for your help.

Regards,
Steve
 
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
if request.form("submit") = "Submit" then

Dim myHTMLstring
Dim url_regex
myHTMLstring = trim(request.form("HTML"))
url_regex = "put your regular expression here"

Dim regex
Dim url_match
Set regex = new RegExp
regex.IgnoreCase = True
regex.Global = True
regex.Pattern = url_regex

For each Match in regex.Execute(myHTMLstring)
Response.write(Match.Value & "<br>")
Next
end if
%>

<html xmlns="<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<form action="findurl2.asp" method="post" name="form1">
<textarea name="HTML" cols="80" rows="20">

<html>
<head>
<title>Hello</title>
</head>
<body>
<a href=" text la la la
<a href=" is some more filler text.
<a href="</body>
</html>
</textarea>
<input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top