<!--#include file="../common/stream.asp"-->
<!--#include file="../common/tools.asp"-->
<%
Set conn=server.CreateObject("adodb.connection")
conn.open "driver={sql server};database=weather;server=(local);uid=sa;pwd="
domain="http://weather.265.com/"
file="index.htm"
url=domain&file
html=getHttpPage(url)
bpos1=InStr(LCase(html),"<body")
bpos2=InStr(LCase(html),"</body>")-InStr(LCase(html),"<body")+7
html=Mid(html,bpos1,bpos2)
html=replaceTest(html,"&(.+);","")
html=Replace(html,"selected","")
html=ReplaceTest(html,"<script{1}.*?>","$1")
html=Replace(html,"</script>","$2")
While(InStr(html,"$1")>0)
Dim s
s=InStr(html,"$1")
length=InStr(html,"$2")-InStr(html,"$1")+2
html=Replace(html,Mid(html,s,length),"")
Wend
html=replaceTest(html,"(/w+)=([#|/w|/d]+)","")
html=replaceTest(html,"<input (.+)>","")
html=LCase(html)
html=Replace(html,"<tbody>","")
html=Replace(html,"</tbody>","")
html=Replace(html,"height=""9""","height=""9"" /")
html=Replace(html,"<br>","")
html="<?xml version=""1.0"" encoding=""gb2312"" ?>"&vbcrlf&html
'response.contentType="text/xml"
'response.write html
response.end
Dim dom,weather,l
Set dom=server.CreateObject("MICROSOFT.XMLDom")
If Not dom.LoadXML(html) Then
response.write "无法创建XML对象"
response.End
End If
Set weather=dom.selectNodes("//table/tr/td/table")
ReDim arr(l,5)
For i=0 To 4
weather(i).parentNode.removeChild(weather(i))
Next
Set weather=dom.selectNodes("//table/tr/td/table")
l=weather.length
Dim sql
For i=0 To l-1
Set provinces=weather(i).selectNodes("tr/td[@rowspan]")
Set cities=weather(i).selectNodes("tr/td[not(@rowspan) and @class='tnt']")
For j=0 To provinces.length-1
province = provinces(j).text
For k=0 To cities.length-1
city = cities(k).text
Set temp=cities(k).NextSibling
temperature=temp.text
Set weat=temp.NextSibling
rep=weat.text
sql="insert into weather (province,city,temperature,morning,afternoon) values ('"&province&"','"&city&"','"&temperature&"','"&Mid(Split(rep," ")(0),4)&"','"&Mid(Split(rep," ")(1),4)&"','"&Mid(Split(rep," ")(2),4)&"',convert(char(10),getdate(),21)"
response.write sql
'conn.execute(sql)
Set temp=Nothing
'----------------------------------
Set temp1=weat.nextsibling
temperature1=temp1.text
Set weat1=temp1.NextSibling
rep1=weat1.text
sql="insert into weather (province,city,temperature,morning,afternoon) values ('"&province&"','"&city&"','"&temperature1&"','"&Mid(Split(rep1," ")(0),4)&"','"&Mid(Split(rep1," ")(1),4)&"','"&Mid(Split(rep1," ")(2),4)&"',convert(char(10),dateadd(dd,1,getdate()),21)"
'conn.execute(sql)
Set rep=Nothing
Set temp1=nothing
'-----------------------------------
Set temp2=weat1.nextsibling
temperature2=temp2.text
Set weat1=temp2.NextSibling
rep2=weat2.text
sql="insert into weather (province,city,temperature,morning,afternoon) values ('"&province&"','"&city&"','"&temperature2&"','"&Mid(Split(rep2," ")(0),4)&"','"&Mid(Split(rep2," ")(1),4)&"','"&Mid(Split(rep2," ")(2),4)&"',convert(char(10),dateadd(dd,1,getdate()),21)"
'conn.execute(sql)
Set rep1=Nothing
Set temp2=Nothing
next
Next
Next
If IsObject(conn) Then
conn.close
Set conn=Nothing
End if
%>