|
本帖最后由 go0517 于 2015-1-7 11:38 编辑
帮忙看一下,怎么修改,提取的数据,汉字才不会乱码。感谢。
Sub test()
Dim strUrl As String, objHttp As Object, strRtn, arrRtn, i%, j, bytes2BSTR, TT
strUrl = "http://www.bjciq.gov.cn:8989/data.do?cmd=query&id=1" & Replace(strUrl, "http://", "") '
Set objHttp = CreateObject("Microsoft.XMLHTTP")
objHttp.Open "GET", strUrl, False
objHttp.Send
Rows(1).NumberFormatLocal = "@" '第二行设置为文本格式
strRtn = Split(objHttp.responsetext, "<table", -1, vbTextCompare)(8) '取 "<table" 之后的内容
strRtn = Split(strRtn, "</tr>", -1, vbTextCompare) '以 "</tr>" 作为分隔符把数据分为行数组
For i = 0 To UBound(strRtn) '行循环
arrRtn = Split(strRtn(i), "<td>", -1, vbTextCompare) '各个字段以 "<td>" 分隔
For j = 1 To UBound(arrRtn) '列循环
Cells(i + 1, j + 1) = Replace(Split(arrRtn(j), "</td>", -1, vbTextCompare)(0), " ", "", 1, -1, vbTextCompare)
Next j
Next i
Set objHttp = Nothing
End Sub
|
|