這裏是一個函數的源代碼我使用的進一步等待處理獲取HTML代碼:VBA WINHTTP沒有映射字符
Public Function DownloadTextFile(url As String) As String
Dim oHTTP As WinHttp.WinHttpRequest
Set oHTTP = New WinHttp.WinHttpRequest
oHTTP.Open Method:="GET", url:=url, async:=False
oHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
'oHTTP.setRequestHeader "Content-Type", "multipart/form-data; "
oHTTP.setRequestHeader "Content-Type", "text/html; charset=utf-8"
oHTTP.Option(WinHttpRequestOption_EnableRedirects) = True
oHTTP.send
Dim success As Boolean
success = oHTTP.waitForResponse()
If Not success Then
Debug.Print "DOWNLOAD FAILED!"
Exit Function
End If
Dim responseText As String
Debug.Print oHTTP.responseText
responseText = oHTTP.responseText
'Set fs = CreateObject("Scripting.FileSystemObject")
'Set a = fs.CreateTextFile("c:\testfile.txt", True, False)
'Set a = fs.CreateTextFile("c:\testfile.txt", True, True)
'a.WriteLine oHTTP.responseText
'a.Close
Set oHTTP = Nothing
DownloadTextFile = responseText
End Function
它適用於大多數的網頁,但對於一些頁面responseText
爲No Mapping for the Unicode character exists in the target multi-byte code page
。
這裏是網頁的一個例子的量,responseText
是No Mapping for the Unicode character exists in the target multi-byte code page
,這裏是一個可疑人物不能被編碼(截圖來自谷歌瀏覽器):
http://imageshack.us/photo/my-images/585/errsource.png/
時不時在同一個網站上,但對於不同的搜索結果這個功能不會產生錯誤,但是,然後,在immidi的HTML源代碼吃的窗口就像?????? ...
任何想法如何使它的工作?
丹尼爾你好。我已檢查了您的建議,並提供了有關問題解決方案的一些進展。 – user2127981 2013-03-03 16:34:49
對於幾個網頁與屏幕截圖中的字符,debuger會在代碼中標記「responseText = oHTTP.responseText」部分代碼,而oHTTP.responseText則包含「No mapping character ...」 – user2127981 2013-03-03 16:48:46
您是否嘗試過:responseText = StrConv (oHTTP.responseText,vbUnicode)? – dee 2013-03-03 17:17:54