如何把别人网页上的数据通过delphi读到本地数据库(见者有分) (300分)

  • 主题发起人 knightlzf
  • 开始时间
给一段ASPVBScript写的远程读取天气预报的程序。源内容是在http://www.t7online.com/上,根据不同的城市代号(该网站自己定义的)得到具体页面。然后对源代码进行一些修改。
很简陋。
该网页为:http://www.beidou7.com/tq.asp

<%
Function wfile(fileName,IsExist,textInfo)
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If IsExist Then
Set Txt = Sys.OpenTextFile(fileName, 2)
Txt.Write(textInfo)
Txt.Close
msg ="恭喜,文件创建成功并保存!"
ElseIf Sys.FileExists(fileName) Then
msg ="抱歉,文件已经存在!"
End If
Set Sys = Nothing
wfile = msg
End Function
%>
<table width="95%" border="0" cellpadding="0" cellspacing="0" class="h">
<tr align="center">
<td><font color="#000000">扬州地区未来3天 天气预报</font></td>
</tr>
<tr align="center" valign="middle">
<td> <%
Function bytes2BSTR(vIn)
dim strReturn
dim i,ThisCharCode,NextCharCode
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &amp;H80 Then
strReturn = strReturn &amp; Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn &amp; Chr(CLng(ThisCharCode) * &amp;H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function

function GetWeatherInfo(cityNumber)
on error resume next
set http=Server.createobject("Msxml2.XMLHTTP")
Http.open "GET","http://www.t7online.com/cgi-bin/citydruck?WMO="&amp;cityNumber&amp;"&amp;LANG=cn&amp;TIME=1082108632",false
Http.send()
if Http.readystate<>4 then exit function
temp=bytes2BSTR(Http.responseBody)
set http=nothing

temp=Left(temp,InStr(temp,CHR(10)&amp;"<table width="&amp;""""&amp;"420")-1)'右边的去除了
temp=Left(temp,InStr(temp,"</table")+7)'右边的去除了
temp=Mid(temp,InStr(temp,"<table")+5)
temp=Mid(temp,InStr(temp,"<table"))
temp=Replace(temp,"/daten","http://www.t7online.com/daten")
temp=Replace(temp,"<font face=""夹发砰"" size=""2"">"," ")
temp=Replace(temp,"</font></td>","</td>")
temp=Replace(temp,"#ffffff","#CCCCCC"""&amp;" clsss=""h")
temp=Replace(temp,"<tr ","<tr bgcolor=""#FFFFFF""")
temp=Replace(temp,"border=""1""","border=""0""")
temp=Replace(temp,"cellspacing=""0""","cellspacing=""1""")
GetWeatherInfo=temp
temp=Replace(temp,"<td ","<td Class=""h""")
response.write(wfile("ld.htm",true,temp))
if err.number<>0 then err.Clear
end function

MyNumber=Request("CityNumber")
if MyNumber="" then
MyNumber="58245"
end if
response.write GetWeatherInfo(MyNumber)
%> </td>
</tr>
<tr>
<td>&amp;nbsp;</td>
</tr>
<tr>
<td align="center" valign="middle"><a href="http://www.beidou7.com">扬州北斗科技有限公司
</a></td>
</tr>
</table>
 
呵呵,只有学习的份了
 
水平太低,学起来就难。努力吧!
 
这个很容易实现
不过就是没有通用的代码
要针对特殊的网页,编码
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
顶部