实例讲解实现抓取网上房产信息的ASP程序(3)


 rs("Contact")=Contact
 rs.update
 rs.close
 set rs=nothing
 end if
 '==================================================

next
function RemoveTag(body)

 Set regEx = New RegExp
 regEx.Pattern = "<[a].*?<\/[a]>"
 regEx.IgnoreCase = True
 regEx.Global = True
 Set Matches = regEx.Execute(body)
 dim i,arr(15),ifexit
 i=0
 j=0
 For Each Match in Matches
  TempStr = Match.Value 
  TempStr=replace(TempStr,"<td>","")
  TempStr=replace(TempStr,"</td>","")
  TempStr=replace(TempStr,"<tr>","")
  TempStr=replace(TempStr,"</tr>","") 
  arr(i)=TempStr 
  i=i+1
  if(i>=15) then
   exit for
  end if
 Next
 Set regEx=nothing
 Set Matches =nothing
 RemoveTag=arr

end function
function RegexHtml(body)
 dim r_arr(47),r_temp
 Set regEx2 = New RegExp
 regEx2.Pattern ="<a.*?<\/a>"
 regEx2.IgnoreCase = True
 regEx2.Global = True
 Set Matches2 = regEx2.Execute(body)
 iii=0
 For Each Match in Matches2

  r_arr(iii)=Match.Value

  iii=iii+1 
 Next
 RegexHtml=r_arr
 set regEx2=nothing
 set Matches2=nothing
end function
'======================================================

conn.close
set conn=nothing
%>
</body>
</html>

 


  function.asp

 <%
'**************************************************
'函数名:gotTopic
'作  用:截字符串,汉字一个算两个字符,英文算一个字符
'参  数:str   ----原字符串
'       strlen ----截取长度
'返回值:截取后的字符串
'**************************************************
function gotTopic(str,strlen)
 if str="" then
  gotTopic=""
  exit function
 end if
 dim l,t,c, i
 str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
 str=replace(str,"?","")
 l=len(str)
 t=0
 for i=1 to l
  c=Abs(Asc(Mid(str,i,1)))
  if c>255 then
   t=t+2
  else
   t=t+1
  end if
  if t>=strlen then
   gotTopic=left(str,i) & "…"
   exit for
  else
   gotTopic=str
  end if
 next
 gotTopic=replace(replace(replace(replace(gotTopic," "," "),chr(34),"""),">",">"),"<","<")
end function
'=========================================================
'函数:RemoveHTML(strHTML)
'功能:去除HTML标记
'参数:strHTML  --要去除HTML标记的字符串
'=========================================================

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/3248.html