guoguo188 发表于 2019-6-18 19:12:14

30RBM求一个能获取内嵌ie完整cookies的代码

本帖最后由 guoguo188 于 2019-6-18 23:09 编辑

一句话描述:用ie登录阿里妈妈网站后通过ie对象获取完整cookies来被winhttp使用困难:网站无法post登录,必须模拟,cookies包含httponly(cookie2 )

达成目标:提取出 cookie2 中的数据 看图
http://www.autoitx.com/data/attachment/forum/month_1609/1609301018a5b12c5f582234e5.png


补充:可参考完善这个帖子的代码即可http://www.autoitx.com/thread-53455-1-1.html
      (这个帖子 我提取出的cookie2 数据无法转换使用,也不知道代码正不正确。)


完整案例,送给有缘人,感谢发哥的帮忙{:1_206:}

#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_UseX64=n
#PRE_Res_requestedExecutionLevel=None
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****

#include <IE.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ARRAY.AU3>
#include <WinAPI.au3>
_AddMyIEVersion(1)
$Form1 = GUICreate("Form1", 623, 600, 192, 114)
$ieobj = _IECreateEmbedded()
GUICtrlCreateObj($ieobj, 0, 0, 617, 393)
_IENavigate($ieobj, "https://login.taobao.com/member/login.jhtml?style=mini&from=alimama")
$Edit1 = GUICtrlCreateEdit("", 0, 400, 617, 140, $WS_VSCROLL)
$button = GUICtrlCreateButton("提交", 270, 560, 80, 30)
GUISetState(@SW_SHOW)

While 1
      $nMsg = GUIGetMsg()
      Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $button

                        MsgBox(0, 0, getjson())
      EndSwitch
;~         $cookies = _IEDocGetObj($ieobj).cookie
;~         If GUICtrlRead($Edit1) <> $cookies Then GUICtrlSetData($Edit1, $cookies)
WEnd
Func getjson($sUrl = 'http://www.taobao.com')      
      Local $iSize = 2048
      Local $tBuffer = DllStructCreate('wchar[' & $iSize & ']')
      Local $Ret = DllCall("wininet.dll", "bool", "InternetGetCookieExW", _
                        'wstr', $sUrl, _
                        'wstr', Null, _
                        "struct*", $tBuffer, _
                        "dword*", $iSize, _
                        "dword", 8192, _
                        "ptr", Null)      
      If @error Or Not $Ret Then Return SetError(1, 0, 0)
      Return DllStructGetData($tBuffer, 1)
EndFunc   ;==>getjson
;接上面

Func _AddMyIEVersion($tag = 1)
        Local $script = @ScriptName
        If Not @Compiled Then
                If $tag = 1 Then
                        RegWrite('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', 'AutoIt3.exe', 'REG_DWORD', '9000')
                        RegWrite('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', 'AutoIt3.exe', 'REG_DWORD', '9000')
                        RegWrite('HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', 'AutoIt3.exe', 'REG_DWORD', '9000')

                        RegWrite('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', 'AutoIt3_x64.exe', 'REG_DWORD', '9000')
                        RegWrite('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', 'AutoIt3_x64.exe', 'REG_DWORD', '9000')
                        RegWrite('HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', 'AutoIt3_x64.exe', 'REG_DWORD', '9000')
                Else
                        RegDelete('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', 'AutoIt3.exe')
                        RegDelete('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', 'AutoIt3.exe')
                        RegDelete('HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', 'AutoIt3.exe')

                        RegDelete('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', 'AutoIt3_x64.exe')
                        RegDelete('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', 'AutoIt3_x64.exe')
                        RegDelete('HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', 'AutoIt3_x64.exe')
                EndIf
        Else
                If $tag = 1 Then
                        RegWrite('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', $script, 'REG_DWORD', '11000')
                        RegWrite('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', $script, 'REG_DWORD', '11000')
                        RegWrite('HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', $script, 'REG_DWORD', '11000')
                Else
                        RegDelete('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', $script)
                        RegDelete('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', $script)
                        RegDelete('HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', $script)
                EndIf
        EndIf
EndFunc   ;==>_AddMyIEVersion







haijie1223 发表于 2019-6-18 19:12:15

Func _WinINet_InternetGetCookieEx($sUrl = 'http://www.taobao.com')       
        Local $iSize = 2048
        Local $tBuffer = DllStructCreate('wchar[' & $iSize & ']')
        Local $Ret = DllCall("wininet.dll", "bool", "InternetGetCookieExW", _
                        'wstr', $sUrl, _
                        'wstr', Null, _
                        "struct*", $tBuffer, _
                        "dword*", $iSize, _
                        "dword", 8192, _
                        "ptr", Null)       
        If @error Or Not $Ret Then Return SetError(1, 0, 0)
        Return DllStructGetData($tBuffer, 1)
EndFunc   ;==>getjson

guoguo188 发表于 2019-6-18 19:21:15

不是要post获取,只要通过调用dll函数InternetgetcookieExW 调用出来即可

cihron 发表于 2019-6-22 22:00:17

好贴,收藏!
页: [1]
查看完整版本: 30RBM求一个能获取内嵌ie完整cookies的代码