用正則表達式來抓取網(wǎng)頁上的手機號碼和Email,其實換個正則表達式還可以抓取很多其他的內(nèi)容,這個是飛鳥制作的,我把代碼貼出來,具體的代碼如下:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title></title> <style type="text/css"> <!-- .STYLE2 {color: #666666} --> </style> </head> <body> <% dim mode mode=request("mode") select case mode case "fenxi" call getTEL() end select '================================================== '過程名:getTEL '================================================== sub getTEL() '單位秒 Server.ScriptTimeout=36000 dim str_url,startid,endid str_url=trim(request("str_url")) startid=trim(request("startid")) endid=trim(request("endid")) str_RegExp=trim(request("str_RegExp")) dim i for i=cint(startid) to cint(endid) call fenxi(getData(replace(str_url,"{id}",i)),str_RegExp) next response.Write("<br><div align=center><input onClick=""javascript:window.open('?mode=textbox','_self');"" type=""button"" name=""Submit"" value=""重新提取""> <br/></div>") response.End() end sub public Function getData(byval RemoteFileUrl) dim Retrieval Set Retrieval = Server.CreateObject("MS"&"XM"&"L2.XM"&"LHT"&"TP") With Retrieval .Open "Get", RemoteFileUrl, False, "", "" .Send if .readyState=4 then if .status = 200 then flag=true GetRemoteData = .ResponseBody else flag=false GetRemoteData ="flase" end if else Set Retrieval = Nothing Exit function end if if Err.Number <> 0 then Err.Clear Set Retrieval = Nothing Exit Function end if End With Set Retrieval = Nothing getData=StreamToText(GetRemoteData) end function Public Function StreamToText(byval stream) dim sm If IsNull(stream) Then StreamToText = "" Else Set sm = server.CreateObject("ADO" & "DB.Stre" & "am"):sm.Open:sm.Type = 1 sm.Write(stream) sm.Position = 0 sm.Type = 2 sm.charset = "gb2312" sm.Position = 0 StreamToText = sm.ReadText() sm.Close:Set sm = Nothing End If End Function '================================================== '過程名:fenxi '================================================== sub fenxi(byval content,byval str_RegExp) dim str,objRegExp,strs,Matches,Match str=replace(replace(content,"<html>",""),"</html>","") Set objRegExp = New Regexp'設(shè)置配置對象 objRegExp.IgnoreCase = True'忽略大小寫 objRegExp.Global = True'設(shè)置為全文搜索 objRegExp.Pattern = str_RegExp strs=trim(str) Set Matches =objRegExp.Execute(strs)'開始執(zhí)行配置 i=0 For Each Match in Matches if InStr(RetStr,Match.Value &",<br/>"&vbcrlf)=0 then i=i+1 RetStr = RetStr & Match.Value &",<br/>"&vbcrlf end if Next response.Write RetStr response.Flush() end sub %> <table border="0" align="center" cellpadding="0" cellspacing="5"> <form name="form1" method="post" action="?"> <input type="hidden" name="mode" value="fenxi"> <tr> <td align="center"> <input name="str_url" type="text" id="str_url" value="http://www.domain.com/show.asp?id={id}" size="50"> <font color="#FF0000">*<span class="STYLE2">{id}為序號</span></font> </td> </tr> <tr> <td align="center">起 <input name="startid" type="text" id="startid" value="1" size="10" onChange="if(/\D/.test(this.value)){alert('“起始ID”只能輸入整數(shù)!');this.value='';}"/> 止 <input name="endid" type="text" id="endid" value="2" size="10" onChange="if(/\D/.test(this.value)){alert('“結(jié)束ID”只能輸入整數(shù)!');this.value='';}"/> <font color="#FF0000">*</font></td> </tr> <tr> <td align="center"><label> <input name="str_RegExp" type="radio" value="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"> EMAIL <input name="str_RegExp" type="radio" value="[1][3|5]\d{9}" checked> 手機 </label></td> </tr> <tr> <td align="center"><input type="submit" name="Submit" value="提交"> <label></label></td> </tr></form> </table> </body> </html>