帆船 发表于 2017-3-18 14:00:08

[已解决]如何让WinHttp组件获取的内容和IE操作获取的相同?

本帖最后由 帆船 于 2017-3-18 16:53 编辑

访问 http://www.catalog.update.microsoft.com/ScopedViewInline.aspx?updateid=975bd6c2-d69f-48f9-bab5-b701e4a44294 通过如下代码产生的两个网页文件,#include <IE.au3>
$sUrl = "http://www.catalog.update.microsoft.com/ScopedViewInline.aspx?updateid=975bd6c2-d69f-48f9-bab5-b701e4a44294"
$WinHttp = ObjCreate("WinHttp.WinHttpRequest.5.1")
$WinHttp.Open('Get', $sUrl, False)
$WinHttp.Send()
$sText = $WinHttp.ResponseText
$hFile = FileOpen("WinHttp.html", 2)
FileWrite($hFile, $sText)
FileClose($hFile)
$oIE = _IECreate($sUrl, 0, 0)
_IELoadWait($oIE)
Sleep(500)
$sText = _IEDocReadHTML($oIE)
_IEQuit($oIE)
$hFile = FileOpen("IEDocRead.html", 2)
FileWrite($hFile, $sText)
FileClose($hFile)

通过WinHttp组件获取的内容文字为英文,

通过IE操作获取的内容文字为中文。
而IE操作一般是不稳定的,不想采用IE的方法,如何让WinHttp组件获取的内容和IE操作获取的相同?

nmgwddj 发表于 2017-3-18 16:06:38

本帖最后由 nmgwddj 于 2017-3-18 16:07 编辑


#include <IE.au3>
$sUrl = "http://www.catalog.update.microsoft.com/ScopedViewInline.aspx?updateid=975bd6c2-d69f-48f9-bab5-b701e4a44294"
$WinHttp = ObjCreate("WinHttp.WinHttpRequest.5.1")
$WinHttp.Open('Get', $sUrl, False)
$WinHttp.setRequestHeader("Accept-Language", "zh-CN")
$WinHttp.Send()
$sText = $WinHttp.ResponseText
$hFile = FileOpen("WinHttp.html", 2)
FileWrite($hFile, $sText)
FileClose($hFile)


帆船 发表于 2017-3-18 16:53:58

回复 2# nmgwddj
啊,非常感谢,又学习了一招!
页: [1]
查看完整版本: [已解决]如何让WinHttp组件获取的内容和IE操作获取的相同?