asp下载html匹配

来源:互联网 发布:js获取frame中的元素 编辑:程序博客网 时间:2024/06/06 15:44
<%url="http://www.mvgod.com/theater/ChongQing/BLWH/"  '//定义要获取源代码的网址,一般是通过变量传递过来HTMLCODE=getHTTPPage(url) '//获取源代码的函数Function getHTTPPage(url)    dim objXML    set objXML=createobject("MSXML2.SERVERXMLHTTP.3.0")  '调用XMLHTTP组件,测试空间是否支持XMLHTTP    objXML.open "GET",url,false 'false表示以同步的方式获取网页代码,了解什么是同步?什么是异步?    objXML.send() '发送    getHTTPPage=bBytesToBstr(objXML.responseBody)'返回信息,同时用函数定义编码    set objXML=nothing'关闭End FunctionFunction bBytesToBstr(body)    dim objstream    set objstream = CreateObject("adodb.stream") '//调用adodb.stream组件    objstream.Type = 1    objstream.Mode =3    objstream.Open    objstream.Write body    objstream.Position = 0    objstream.Type = 2    objstream.Charset = "UTF-8" '转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP调用有中文字符的网页得到的将是乱码    bBytesToBstr = objstream.ReadText    objstream.Close    set objstream = nothingend FunctionFunction RegExpTest(patrn, strng)Dim regEx, retVal '建立变量。Set regEx = New RegExp '建立正则表达式。regEx.Pattern = patrn '设置模式。regEx.IgnoreCase = False '设置是否区分大小写。regEx.Global = TrueSet retVal = regEx.Execute(strng) '执行搜索测试。For Each Match in retVal '遍历匹配集合。RetStr = RetStr & Match.ValueNextRegExpTest = RetStrEnd Functionresponse.write RegExpTest("<table cellpadding=""1"" cellspacing=""1"" border=""0"" id=""guide""([\s\S]*)</table>", HTMLCODE)%>