asp学习网: 首页 >> 正则表达式 >> 抓取html中的内容

抓取html中的内容

另存为asp文件执行,可以去掉远程抓取后的html标记。

<%
Option Explicit

Function stripHTML(strHTML)
''Strips the HTML tags from strHTML

 Dim objRegExp, strOutput
 Set objRegExp = New Regexp

 objRegExp.IgnoreCase = True
 objRegExp.Global = True
 objRegExp.Pattern = "<.+?>"

 ''Replace all HTML tag matches with the empty string
 strOutput = objRegExp.Replace(strHTML, "")
 
 ''Replace all < and > with < and >
 strOutput = Replace(strOutput, "<", "<")
 strOutput = Replace(strOutput, ">", ">")
 
 stripHTML = strOutput    ''Return the value of strOutput

 Set objRegExp = Nothing
End Function


%>

<form method="post" id=form1 name=form1>
 <b>Enter an HTML String:</b><br>
 <textarea name="txtHTML" cols="50" rows="8" wrap="virtual"><%=Request("txtHTML")%></textarea>
 <p>
 <input type="submit" value="Strip HTML Tags!" id=submit1 name=submit1>
</form>

<% if Len(Request("txtHTML")) > 0 then %>
   <p><hr><p>
   <b><u>View of string <i>with no</i> HTML stripping:</u></b><br>
   <xmp>
   <%=Request("txtHTML")%>
   </xmp><p>
   <b><u>View of string <i>with</i> HTML stripping:</u></b><br>
   <pre>
   <%=StripHTML(Request("txtHTML"))%>
   </pre>
<% End If %> from:asp学习网/title:抓取html中的内容/ time:2006-4-26 1:59:58

本文主题抓取html中的内容

asp教程 ©2006-2007 aspxuexi.com | 关于站点 | 版权隐私 | 站内搜索
复制或者翻版 请于夜间进行