使用Inet控件,我用下面这段代码想获取网页中指定的天气预报的内容,但是总是不能正确获取,都是网页代码的全部内容都显示出来的,请高手指点一下,谢谢!!!
Private Sub Form_Load()
GetWeatherReport
End Sub
Private Sub icWeather_StateChanged(ByVal State As Integer)
Dim strData As String, strBuf As String
Dim l As Long, k As Long, strTemp As Variant
Dim weatherstart As String
Dim Tempstart As String
Tempstart = "最高温度:</td><td><font class=temp6>"
weatherstart = "<td class='weatherState' width='62%'>"
If State = icResponseCompleted Then
'请求已结束,数据已全部接收
'将缓冲区数据转移到程序变量中
strBuf = icWeather.GetChunk(1024)
Do While strBuf <> ""
DoEvents
strData = strData & strBuf
strBuf = icWeather.GetChunk(1024)
Loop
icWeather.Cancel
'获取温度
l = InStr(strData, Tempstart) + Len(Tempstart)
k = InStr(l, strData, "</font>")
strTemp = Mid$(strData, l, k - l)
Label1.Caption = strTemp
'获取天气
l = InStr(l, strData, WeathStart) + Len(WeathStart)
k = InStr(l, strData, "</td>")
strTemp = Mid(strData, l, k - l)
Label2.Caption = strTemp
ElseIf State = icError Then
'请求数据时发生错误
MsgBox "发生错误!"
'End
End If
End Sub
Public Sub GetWeatherReport()
'获取选择城市的天气预报
Form1.icWeather.Execute "http://www.elong.com/weather/ForecaseCity.aspx?city=广州"
End Sub
[此贴子已经被作者于2007-3-10 11:29:30编辑过]