当前位置:首页 > 网络编程 > WEB编程 > ASP > 实例讲解asp抓取网上房产信息

实例讲解asp抓取网上房产信息

点击次数:18 次 发布日期:2008-11-26 14:42:00 作者:源代码网
源代码网推荐

源代码网整理以下附:抓取信息的详细页面事例
源代码网推荐

 

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
源代码网推荐<!-- #include file="conn.asp" -->
源代码网推荐<!-- #include file="inc/function.asp" -->
源代码网推荐<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
源代码网推荐"http://www.w3.org/TR/html4/loose.dtd">
源代码网推荐<html>
源代码网推荐<head>
源代码网推荐<title>Untitled Document</title>
源代码网推荐<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
源代码网推荐<meta http-equiv="refresh" content="300;URL=steal_house.asp">
源代码网推荐</head>
源代码网推荐<body>
源代码网推荐<%
源代码网推荐on error resume next
源代码网推荐"
源代码网推荐Server.ScriptTimeout = 999999
源代码网推荐"========================================================
源代码网推荐"字符编码函数
源代码网推荐"====================================================
源代码网推荐Function BytesToBstr(body,code)
源代码网推荐dim objstream
源代码网推荐set objstream = Server.CreateObject("adodb.stream")
源代码网推荐objstream.Type = 1
源代码网推荐objstream.Mode =3
源代码网推荐objstream.Open
源代码网推荐objstream.Write body
源代码网推荐objstream.Position = 0
源代码网推荐objstream.Type = 2
源代码网推荐objstream.Charset =code
源代码网推荐BytesToBstr = objstream.ReadText
源代码网推荐objstream.Close
源代码网推荐set objstream = nothing
源代码网推荐End Function
源代码网推荐"取行字符串在另一字符串中的出现位置
源代码网推荐Function Newstring(wstr,strng)
源代码网推荐Newstring=Instr(lcase(wstr),lcase(strng))
源代码网推荐if Newstring<=0 then Newstring=Len(wstr)
源代码网推荐End Function
源代码网推荐"替换字符串函数
源代码网推荐function ReplaceStr(ori,str1,str2)
源代码网推荐ReplaceStr=replace(ori,str1,str2)
源代码网推荐end function
源代码网推荐"====================================================
源代码网推荐function ReadXml(url,code,start,ends)
源代码网推荐set oSend=createobject("Microsoft.XMLHTTP")
源代码网推荐SourceCode = oSend.open ("GET",url,false)
源代码网推荐oSend.send()
源代码网推荐ReadXml=BytesToBstr(oSend.responseBody,code )
源代码网推荐start=Instr(ReadXml,start)
源代码网推荐ReadXml=mid(ReadXml,start)
源代码网推荐ends=Instr(ReadXml,ends)
源代码网推荐ReadXml=left(ReadXml,ends-1)
源代码网推荐end function
源代码网推荐function SubStr(body,start,ends)
源代码网推荐start=Instr(body,start)
源代码网推荐SubStr=mid(body,start+len(start)+1)
源代码网推荐ends=Instr(SubStr,ends)
源代码网推荐SubStr=left(SubStr,ends-1)
源代码网推荐end function
源代码网推荐dim getcont,NewsContent
源代码网推荐dim url,title
源代码网推荐url="http://www.***.com""新闻网址
源代码网推荐getcont=ReadXml(url,"gb2312","<table class=k2 border=""0""","</table>")
源代码网推荐getcont=RegexHtml(getcont)
源代码网推荐dim KeyId,NewsClass,City,Position,HouseType,Level,Area,Price,Demostra
源代码网推荐dim ContactMan,Contact
源代码网推荐for i=2 to ubound(getcont)
源代码网推荐response.Write(getcont(i)&"__<br>")

tempLink=mid(getcont(i),instr(getcont(i),"href=""")+6,instr(getcont(i),"""
源代码网推荐onClick")-10)
源代码网推荐tempLink=replace(tempLink,"../","")

response.Write(i&":"&tempLink&"<br>")
源代码网推荐NewsContent=ReadXml(tempLink,"gb2312","<td valign=""bottom""
源代码网推荐width=""400"">","<hr width=""760""
源代码网推荐noshade size=""1"" color=""#808080"">
源代码网推荐")
源代码网推荐NewsContent=RemoveHtml(NewsContent)
源代码网推荐NewsContent=replace(NewsContent,VbCrLf,"")
源代码网推荐NewsContent=replace(NewsContent,vbNewLine,"")
源代码网推荐NewsContent=replace(NewsContent," ","")
源代码网推荐NewsContent=replace(NewsContent," ","")
源代码网推荐NewsContent=replace(NewsContent,"&nbsp;","")
源代码网推荐NewsContent=replace(NewsContent," ","")
源代码网推荐NewsContent=replace(NewsContent,chr(10),"")
源代码网推荐NewsContent=replace(NewsContent,chr(13),"")
源代码网推荐"===============get Content=======================
源代码网推荐response.Write(NewsContent)
源代码网推荐KeyId=SubStr(NewsContent,"列号:","信息类别:")
源代码网推荐NewsClass=SubStr(NewsContent,"类别:","所在城市:")
源代码网推荐City=SubStr(NewsContent,"城市:","房屋具体位置:")
源代码网推荐Position=SubStr(NewsContent,"位置:","房屋类型:")
源代码网推荐HouseType=SubStr(NewsContent,"类型:","楼层:")
源代码网推荐Level=SubStr(NewsContent,"楼层:","使用面积:")
源代码网推荐Area=SubStr(NewsContent,"面积:","房价:")
源代码网推荐Price=SubStr(NewsContent,"房价:","其他说明:")
源代码网推荐Demostra=SubStr(NewsContent,"说明:","联系人:")
源代码网推荐ContactMan=SubStr(NewsContent,"联系人:","联系方式:")
源代码网推荐Contact=SubStr(NewsContent,"联系方式:","信息来源:")
源代码网推荐response.Write("总序列号:"&KeyId&"<br>")
源代码网推荐response.Write("信息类别:"&NewsClass&"<br>")
源代码网推荐response.Write("所在城市:"&City&"<br>")
源代码网推荐response.Write("房屋具体位置:"&Position&"<br>")
源代码网推荐response.Write("房屋类型:"&HouseType&"<br>")
源代码网推荐response.Write("楼层:"&Level&"<br>")
源代码网推荐response.Write("使用面积:"&Area&"<br>")
源代码网推荐response.Write("房价:"&Price&"<br>")
源代码网推荐response.Write("其他说明:"&Demostra&"<br>")
源代码网推荐response.Write("联系人:"&ContactMan&"<br>")
源代码网推荐response.Write("联系方式:"&Contact&"<br>")
源代码网推荐"title=RemoveHTML(aa(i))
源代码网推荐"response.Write("title:"&title)
源代码网推荐for n=0 to application.Contents.count
源代码网推荐if(application.Contents(n)=KeyId) then
源代码网推荐ifexit=true
源代码网推荐end if
源代码网推荐next
源代码网推荐if not ifexit then
源代码网推荐application(time&i)=KeyId
源代码网推荐"添加到数据库
源代码网推荐"====================================================
源代码网推荐set rs=server.CreateObject("adodb.recordset")
源代码网推荐rs.open "select top 1 * from news order by id desc",conn,3,3
源代码网推荐rs.addnew
源代码网推荐rs("NewsClass")=NewsClass
源代码网推荐rs("City")=City
源代码网推荐rs("Position")=Position
源代码网推荐rs("HouseType")=HouseType
源代码网推荐rs("Level")=Level
源代码网推荐rs("Area")=Area
源代码网推荐rs("Price")=Price
源代码网推荐rs("Demostra")=Demostra
源代码网推荐rs("ContactMan")=ContactMan
源代码网推荐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,"&nbsp;"," "),"&quot;",chr(34)),"&gt;",">"),"&lt;","<")
源代码网推荐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," ","&nbsp;"),chr(34),"&quot;"),">","&gt;"),"<","&lt;")
源代码网推荐end function
源代码网推荐"=========================================================
源代码网推荐"函数:RemoveHTML(strHTML)
源代码网推荐"功能:去除HTML标记
源代码网推荐"参数:strHTML --要去除HTML标记的字符串
源代码网推荐"=========================================================
源代码网推荐Function RemoveHTML(strHTML)
源代码网推荐Dim objRegExp, Match, Matches
源代码网推荐Set objRegExp = New Regexp
源代码网推荐objRegExp.IgnoreCase = True
源代码网推荐objRegExp.Global = True
源代码网推荐"取闭合的<>
源代码网推荐objRegExp.Pattern = "<.+?>"
源代码网推荐"进行匹配
源代码网推荐Set Matches = objRegExp.Execute(strHTML)
源代码网推荐" 遍历匹配集合,并替换掉匹配的项目
源代码网推荐For Each Match in Matches
源代码网推荐strHtml=Replace(strHTML,Match.Value,"")
源代码网推荐Next
源代码网推荐RemoveHTML=strHTML
源代码网推荐Set objRegExp = Nothing
源代码网推荐set Matches=nothing
源代码网推荐End Function
源代码网推荐%>

源代码网整理以下
源代码网推荐  conn.asp
源代码网推荐<%
源代码网推荐"on error resume next
源代码网推荐set conn=server.CreateObject("adodb.connection")
源代码网推荐con= "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("stest.mdb")

源代码网整理以下conn.open con
源代码网推荐sub connclose
源代码网推荐conn.close
源代码网推荐set conn=nothing
源代码网推荐end sub
源代码网推荐%>
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华