我将使用VBA中的Microsoft.XMLHTTP来获取网页正文。在这个过程中,像é这样的字符会被替换成"?"或其他无用的字符。
以下是基本代码:
有没有什么方法可以保留特殊字符并检索页面?
注意: 我还尝试过使用以下请求头,但没有成功:
解决方案: 感谢Ben.Vineyard(以及一些搜索),我能够使用以下代码提取带有重音符号的字符。
以下是基本代码:
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
objHTTP.Open "GET", ThisWebPage, False
objHTTP.setRequestHeader "Content-Type", _
"application/x-www-form-urlencoded; charset=UTF-8"
objHTTP.Send ("")
strResponse = objHTTP.responseText
有没有什么方法可以保留特殊字符并检索页面?
注意: 我还尝试过使用以下请求头,但没有成功:
objHTTP.setRequestHeader "Content-Type", "content=text/html; charset=iso-8859-1"
提前感谢。解决方案: 感谢Ben.Vineyard(以及一些搜索),我能够使用以下代码提取带有重音符号的字符。
' Create the XMLHTTP object
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
' Send the request
objHTTP.Open "GET", WhatWebPage, False
objHTTP.Send ("")
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
With BinaryStream
.Type = adTypeBinary
.Open
.Write objHTTP.ResponseBody
'Change stream type To binary
.Position = 0
.Type = adTypeText
'Specify charset For the source text (unicode) data.
.Charset = "iso-8859-1"
'Open the stream And get binary data from the object
strResponse = .ReadText
End With