kevinch 发表于 2011-4-6 10:08:42

用_inetgetsource读取源码并用binarytostring转为utf-8格式后有乱码?

如题$s_Str=BinaryToString(_inetgetsource("http://so.56.com/index?key=Exceltip"),4)得到的源代码不全,且有乱码,不知如何可以解决,现在只能用打开网页的方式取得代码暂时替代,请高手指点为盼。{:face (396):}

qq1244521 发表于 2011-4-6 13:18:50

{:face (245):}一头雾水啊

kevinch 发表于 2011-4-6 15:41:31

就是我想利用一楼的那段代码得到对应网页的源代码,网页是用utf-8格式编码的,我转换成utf-8格式后,其中很多中文消失了,代之为?,与打开网页取得的源代码不相同,也就是说有一部分中文消失不见啦,想看看大家有没有遇到这样的情况,以及是怎么解决的。毕竟打开网页再取代码不是一个好办法。

ceoguang 发表于 2011-4-6 23:03:55

$s_Str=BinaryToString(_inetgetsource("http://so.56.com/index?key=Exceltip",False),4)

kevinch 发表于 2011-4-7 07:11:25


ceoguang 发表于 2011-4-6 23:03 http://www.autoitx.com/images/common/back.gif
多谢指教,测试后再回复{:face (396):}

kevinch 发表于 2011-4-7 10:17:36

是我的inet.au3太落伍了吗?加了false后什么也取不到了,而函数提示里也没有第二个参数,版主能分享一下你的inet.au3吗?

ceoguang 发表于 2011-4-7 16:48:35


Func _INetGetSource($s_URL, $bString = True)
        Local $sString = InetRead($s_URL, 1)
        Local $nError = @error, $nExtended = @extended
        If $bString Then $sString = BinaryToString($sString)
        Return SetError($nError, $nExtended, $sString)
EndFunc   ;==>_INetGetSource

hongshow 发表于 2011-4-7 16:51:09

来学习下...............

auto 发表于 2011-4-7 18:03:21

搜索,论坛有解决方案

kevinch 发表于 2011-4-8 07:06:00

Func _INetGetSource($s_URL, $s_Header = '')
       
        If StringLeft($s_URL, 7) <> 'http://' And StringLeft($s_URL, 8) <> 'https://' Then $s_URL = 'http://' & $s_URL
       
        Local $h_DLL = DllOpen("wininet.dll")
       
        Local $ai_IRF, $s_Buf = ''
       
        Local $ai_IO = DllCall($h_DLL, 'int', 'InternetOpen', 'str', "AutoIt v3", 'int', 0, 'int', 0, 'int', 0, 'int', 0)
        If @error Or $ai_IO = 0 Then
                DllClose($h_DLL)
                SetError(1)
                Return ""
        EndIf
       
        Local $ai_IOU = DllCall($h_DLL, 'int', 'InternetOpenUrl', 'int', $ai_IO, 'str', $s_URL, 'str', $s_Header, 'int', StringLen($s_Header), 'int', 0x80000000, 'int', 0)
        If @error Or $ai_IOU = 0 Then
                DllCall($h_DLL, 'int', 'InternetCloseHandle', 'int', $ai_IO)
                DllClose($h_DLL)
                SetError(1)
                Return ""
        EndIf
       
        Local $v_Struct = DllStructCreate('udword')
        DllStructSetData($v_Struct, 1, 1)
       
        While DllStructGetData($v_Struct, 1) <> 0
                $ai_IRF = DllCall($h_DLL, 'int', 'InternetReadFile', 'int', $ai_IOU, 'str', '', 'int', 256, 'ptr', DllStructGetPtr($v_Struct))      
                $s_Buf &= StringLeft($ai_IRF, DllStructGetData($v_Struct, 1))
        WEnd
       
        DllCall($h_DLL, 'int', 'InternetCloseHandle', 'int', $ai_IOU)
        DllCall($h_DLL, 'int', 'InternetCloseHandle', 'int', $ai_IO)
        DllClose($h_DLL)
        Return $s_Buf
EndFunc   ;==>_INetGetSource这是我的Inet.au3里的_inetgetsource的代码,奇怪,为何差别这么大呢?

kevinch 发表于 2011-4-8 12:18:34

大家再帮忙看看,搜索论坛上的帖子,好像结果还是未彻底解决的,难道真的只有打开网页读取源代码一途啦?

骗子 发表于 2011-4-10 17:33:54

只用过一次_inetgetsource
但是得到的源代码和打开网页后读取HTML的内容有很大的差别,不知道是怎么回事
页: [1]
查看完整版本: 用_inetgetsource读取源码并用binarytostring转为utf-8格式后有乱码?