http://www.w3.org/TR/html4/loose.dtd"> http://www.奸淫.com"'新闻网址 getcont=ReadXml(url,"gb2312","") getcont=RegexHtml(getcont) dim KeyId,NewsClass,City,P" /> 
快捷搜索:  test  as

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

附:抓守信息的具体页面事例

%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

http://www.w3.org/TR/html4/loose.dtd">

http://www.奸淫.com"'新闻网址

getcont=ReadXml(url,"gb2312","")

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)&"__

")

tempLink=mid(getcont(i),instr(getcont(i),"href=""")+6,instr(getcont(i),"""

onClick")-10)

tempLink=replace(tempLink,"../","")

response.Write(i&":"&tempLink&"

")

NewsContent=ReadXml(tempLink,"gb2312","

width=""400"">","

")

NewsContent=RemoveHtml(NewsContent)

NewsContent=replace(NewsContent,VbCrLf,"")

NewsContent=replace(NewsContent,vbNewLine,"")

NewsContent=replace(NewsContent," ","")

NewsContent=replace(NewsContent," ","")

NewsContent=replace(NewsContent," ","")

NewsContent=replace(NewsContent,"\n","")

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&"

")

response.Write("信息种别:"&NewsClass&"

")

response.Write("所在城市:"&City&"

")

response.Write("房屋详细位置:"&Position&"

")

response.Write("房屋类型:"&HouseType&"

")

response.Write("楼层:"&Level&"

")

response.Write("应用面积:"&Area&"

")

response.Write("房价:"&Price&"

")

response.Write("其他阐明:"&Demostra&"

")

response.Write("联系人:"&ContactMan&"

")

response.Write("联系要领:"&Contact&"

")

'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 = ""

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,"

","")

TempStr=replace(TempStr,"","")

TempStr=replace(TempStr,"

","")

TempStr=replace(TempStr,"","")

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 =""

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

%>

function.asp

",">"),"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),"""),">",">"),"

objRegExp.Pattern = ""

'进行匹配

Set Matches = objRegExp.Execute(strHTML)

' 遍历匹配聚拢,并调换掉落匹配的项目

For Each Match in Matches

strHtml=WordStr(strHTML,Match.Value,"")

Next

RemoveHTML=strHTML

Set objRegExp = Nothing

set Matches=nothing

End Function

%>

conn.asp

您可能还会对下面的文章感兴趣: