VB中如何提取网页中指定的内容?

2024-12-12 22:10:49
推荐回答(1个)
回答1:

Function GetText(url)
On Error GoTo 警告
Dim obj
Set obj = CreateObject("Microsoft.XMLHTTP")
obj.Open "GET", url, False
obj.Send
GetText = StrConv(obj.responseBody, vbUnicode)
Exit Function
警告:
MsgBox "网络未连接!"
End Function
Private Sub Command1_Click()
http = "http://www.cailele.com/static/ssc/newlyopenlist.xml"
T = GetText(http)
i = InStr(1, T, " i1 = InStr(i, T, "")
T = Mid$(T, i, i1 - i)
T1 = Split(T, "/>")
ReDim T2(1, UBound(T1))
For i = 0 To UBound(T1)
T2(0, i) = Mid(T1(i), 14, 11)
T2(1, i) = Mid(T1(i), 37, 9)
Next
With MSFlexGrid1
.Cols = 2
.Rows = UBound(T2, 2) + 2
.TextMatrix(0, 0) = "期号"
.TextMatrix(0, 1) = "号码"
For i = 0 To UBound(T2, 2)
.TextMatrix(i + 1, 0) = T2(0, i)
.TextMatrix(i + 1, 1) = T2(1, i)
Next
End With
End Sub

’辛苦帮你搞定了,请采纳和赞同!谢谢!