執行個體講解asp抓取網上房產的資訊

來源:互聯網
上載者:User
getnews.asp

作者:淘特網

出處:淘特網

註:轉載請註明出處

 <%@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," ","") 
 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&"<br>")
 response.Write("資訊類別:"&NewsClass&"<br>")
 response.Write("所在城市:"&City&"<br>")
 response.Write("房屋具體位置:"&Position&"<br>")
 response.Write("房屋類型:"&HouseType&"<br>



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.