主頁(yè) > 知識(shí)庫(kù) > 實(shí)例講解實(shí)現(xiàn)抓取網(wǎng)上房產(chǎn)信息的ASP程序

實(shí)例講解實(shí)現(xiàn)抓取網(wǎng)上房產(chǎn)信息的ASP程序

熱門(mén)標(biāo)簽:蘭州智能語(yǔ)音電銷(xiāo)機(jī)器人功能 離線(xiàn)電子地圖標(biāo)注軟件注冊(cè) 辦理400電話(huà)一年多少錢(qián) 寧夏怎么申請(qǐng)400電話(huà) 外呼回?fù)芟到y(tǒng)圖片 企數(shù)外呼系統(tǒng)能用多久 為什么外呼系統(tǒng)需要預(yù)存話(huà)費(fèi)呢 常用地圖標(biāo)注范圍點(diǎn) 咸陽(yáng)銷(xiāo)售外呼系統(tǒng)
%@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
'========================================================
'字符編碼函數(shù)
'====================================================
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

'取行字符串在另一字符串中的出現(xiàn)位置
Function Newstring(wstr,strng)
        Newstring=Instr(lcase(wstr),lcase(strng))
        if Newstring=0 then Newstring=Len(wstr)
End Function
'替換字符串函數(shù)
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"'新聞網(wǎng)址knowsky.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,"\n","")
 NewsContent=replace(NewsContent,chr(10),"")
 NewsContent=replace(NewsContent,chr(13),"")
 '===============get Content=======================
 response.Write(NewsContent)
 KeyId=SubStr(NewsContent,"列號(hào):","信息類(lèi)別:")
 NewsClass=SubStr(NewsContent,"類(lèi)別:","所在城市:")
 City=SubStr(NewsContent,"城市:","房屋具體位置:")
 Position=SubStr(NewsContent,"位置:","房屋類(lèi)型:")
 HouseType=SubStr(NewsContent,"類(lèi)型:","樓層:")
 Level=SubStr(NewsContent,"樓層:","使用面積:")
 Area=SubStr(NewsContent,"面積:","房?jī)r(jià):")
 Price=SubStr(NewsContent,"房?jī)r(jià):","其他說(shuō)明:")
 Demostra=SubStr(NewsContent,"說(shuō)明:","聯(lián)系人:")
 ContactMan=SubStr(NewsContent,"聯(lián)系人:","聯(lián)系方式:")
 Contact=SubStr(NewsContent,"聯(lián)系方式:","信息來(lái)源:")
 response.Write("總序列號(hào):"KeyId"br>")
 response.Write("信息類(lèi)別:"NewsClass"br>")
 response.Write("所在城市:"City"br>")
 response.Write("房屋具體位置:"Position"br>")
 response.Write("房屋類(lèi)型:"HouseType"br>")
 response.Write("樓層:"Level"br>")
 response.Write("使用面積:"Area"br>")
 response.Write("房?jī)r(jià):"Price"br>")
 response.Write("其他說(shuō)明:"Demostra"br>")
 response.Write("聯(lián)系人:"ContactMan"br>")
 response.Write("聯(lián)系方式:"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(timei)=KeyId
 '添加到數(shù)據(jù)庫(kù)
 '====================================================
 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

 %
'**************************************************
'函數(shù)名:gotTopic
'作  用:截字符串,漢字一個(gè)算兩個(gè)字符,英文算一個(gè)字符
'參  數(shù):str   ----原字符串
'       strlen ----截取長(zhǎng)度
'返回值:截取后的字符串
'**************************************************
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
'=========================================================
'函數(shù):RemoveHTML(strHTML)
'功能:去除HTML標(biāo)記
'參數(shù):strHTML  --要去除HTML標(biāo)記的字符串
'=========================================================
Function RemoveHTML(strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp

objRegExp.IgnoreCase = True
objRegExp.Global = True
'取閉合的>
objRegExp.Pattern = ".+?>"
'進(jìn)行匹配
Set Matches = objRegExp.Execute(strHTML)

' 遍歷匹配集合,并替換掉匹配的項(xiàng)目
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
%>
 


  附:抓取信息的詳細(xì)頁(yè)面事例

總序列號(hào):

479280  

信息類(lèi)別:

出租

所在城市:

濟(jì)南

房屋具體位置:

華龍路華信路交界口

房屋類(lèi)型:

其他

樓層:

六層

使用面積:

24~240 平方米之間

房?jī)r(jià):

0  [租賃:元/月,買(mǎi)賣(mài):萬(wàn)元/套]

其他說(shuō)明:

華信商務(wù)樓3至6層小空間對(duì)外出租(0.5元/平起),本樓屬純商務(wù)辦公投資使用,可用于辦公寫(xiě)字間,周邊設(shè)施齊全、交通便利(37、80、K95在本樓前經(jīng)過(guò)),全產(chǎn)權(quán)、市證,樓內(nèi)設(shè)施包括水、電、暖、電梯設(shè)施齊全,有意者可電訊!

聯(lián)系人:

魯、王

聯(lián)系方式:

88017966、86812217

信息來(lái)源:

2005-8-4 8:28:55  來(lái)自:218.98.86.175

點(diǎn)擊次數(shù):

19

標(biāo)簽:昌都 泰州 咸陽(yáng) 鐵嶺 昆明 家電維修 麗江 溫州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《實(shí)例講解實(shí)現(xiàn)抓取網(wǎng)上房產(chǎn)信息的ASP程序》,本文關(guān)鍵詞  實(shí)例,講解,實(shí)現(xiàn),抓取,網(wǎng)上,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《實(shí)例講解實(shí)現(xiàn)抓取網(wǎng)上房產(chǎn)信息的ASP程序》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于實(shí)例講解實(shí)現(xiàn)抓取網(wǎng)上房產(chǎn)信息的ASP程序的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章