30RBM求一个能获取完整cookies的方法
一句话描述:用ie登录阿里妈妈网站后通过ie对象获取完整cookies来被winhttp使用困难:网站无法post登录,必须模拟,cookies包含httponly
请大牛指教一下 ,难度大的我加
示例代码如下:
#include <IE.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$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
getjson()
EndSwitch
$cookies = _IEDocGetObj($ieobj).cookie
If GUICtrlRead($Edit1) <> $cookies Then GUICtrlSetData($Edit1, $cookies)
WEnd
Func getjson()
$url = "http://pub.alimama.com/pubauc/getCommonCampaignByItemId.json?itemId=528423266110"
$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP.Open("get", $url, False)
$oHTTP.setRequestHeader("Cookie", $cookies)
$oHTTP.Send()
$dxjson = $oHTTP.responsebody
MsgBox(0,0,BinaryToString($dxjson, 4))
EndFunc ;==>getjson
用InternetGetCookieEx 应该可以实现,
应为对dllcall完全不懂,临时突击了一下
$url = _IEPropertyGet($ieobj ,"locationurl")
$dllsize = "1024"
$getcookies = DllCall("wininet.dll" ,"wstr" ,"InternetGetCookieEx" ,"wstr" ,$url ,"PTR" ,"NULL" ,"wstr" "" ,"DWORD" ,$dllsize ,"DWORD" ,"INTERNET_COOKIE_HTTPONLY" ,"PTR" ,"NULL")
_ArrayDisplay($getcookies)
然后还是获取不到
BOOL InternetGetCookieEx(
_In_ LPCTSTR lpszURL,
_In_ LPCTSTR lpszCookieName,
_Inout_opt_ LPTSTRlpszCookieData,
_Inout_ LPDWORD lpdwSize,
_In_ DWORD dwFlags,
_In_ LPVOIDlpReserved
);
按部就班一步一步post呗 回复 3# haijie1223
阿里系的网站要能post成功简直是比登天还难 回复 4# cxlater
对Cookies不太明白,不过那个api应该是这么写:#include <ARRAY.AU3>
#include <WinAPI.au3>
Global $INTERNET_COOKIE_HTTPONLY = 8192 ;Requires IE 8 or higher
Global $INTERNET_COOKIE_THIRD_PARTY = 131072
Global $INTERNET_FLAG_RESTRICTED_ZONE = 16
Global $sUrl = '你的网址'
Global $sCookieName = '网站的cookies名称'
Global $tSize = DllStructCreate("dword")
Global $tBuffer = DllStructCreate('char')
Global $getcookies = DllCall("wininet.dll", _
"bool", "InternetGetCookieExW", _
'wstr', $sUrl, _
'wstr', $sCookieName, _
"ptr", DllStructGetPtr($tBuffer), _
"ptr", DllStructGetPtr($tSize), _
"dword", $INTERNET_COOKIE_HTTPONLY, _
"ptr", Null _
)
If Not _WinAPI_GetLastError() Then ConsoleWrite(DllStructGetData($tBuffer, 1) & @CRLF)
ConsoleWrite(_WinAPI_GetLastError() & @CRLF)
_ArrayDisplay($getcookies) 好像有另外一个API函数,忘了什么了 还是,淘宝的登录页面,有一个cookie2的cookie字段, 只要能获取到他就ok了
完整可重现代码:
#include <IE.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ARRAY.AU3>
#include <WinAPI.au3>
$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
getjson()
EndSwitch
$cookies = _IEDocGetObj($ieobj).cookie
If GUICtrlRead($Edit1) <> $cookies Then GUICtrlSetData($Edit1, $cookies)
WEnd
Func getjson()
Global $INTERNET_COOKIE_HTTPONLY = 8192 ;Requires IE 8 or higher
Global $INTERNET_COOKIE_THIRD_PARTY = 131072
Global $INTERNET_FLAG_RESTRICTED_ZONE = 16
Global $sUrl = _IEPropertyGet($ieobj ,"locationurl")
Global $sCookieName = 'cookie2'
Global $tSize = DllStructCreate("dword")
Global $tBuffer = DllStructCreate('char')
Global $getcookies = DllCall("wininet.dll", _
"bool", "InternetGetCookieExW", _
'wstr', $sUrl, _
'wstr', $sCookieName, _
"ptr", DllStructGetPtr($tBuffer), _
"ptr", DllStructGetPtr($tSize), _
"dword", $INTERNET_COOKIE_HTTPONLY, _
"ptr", Null _
)
If Not _WinAPI_GetLastError() Then ConsoleWrite(DllStructGetData($tBuffer, 1) & @CRLF)
ConsoleWrite(_WinAPI_GetLastError() & @CRLF)
_ArrayDisplay($getcookies)
;~
;~ $url = "http://pub.alimama.com/pubauc/getCommonCampaignByItemId.json?itemId=528423266110"
;~ $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
;~ $oHTTP.Open("get", $url, False)
;~ $oHTTP.setRequestHeader("Cookie", ClipGet())
;~ $oHTTP.Send()
;~ $dxjson = $oHTTP.responsebody
;~ MsgBox(0, 0, BinaryToString($dxjson, 4))
EndFunc ;==>getjson
是做阿里妈妈链接转换吗?
做好的代码分我! 淘宝的我做过httponly 的COOKIE,当时弄了很多天
我发的浏览器 XIE里面好像有的
_WinINet_InternetSetCookie
必须在内嵌窗口内,我好像记得
_IEEx_InternetSetCookie("http://www.iqiyi.com/", $__IQIYI)
Func _IEEx_InternetSetCookie($__URL, $__VALUE)
$__COOKIE = StringRegExp($__VALUE, "\S+\=[^;]*", 3)
For $i = 0 To UBound($__COOKIE) - 1
$___COOKIE = StringRegExp($__COOKIE[$i], "(\A\S+?)=([^;]*)", 3)
_WinINet_InternetSetCookie($__URL, $___COOKIE, $___COOKIE)
Next
EndFunc ;==>_IEEx_InternetSetCookie
还可以把COOKIE 自定义路径 session 无法保存在本地,但是可以自己读取,保存,然后用我上面的代码来恢复! 回复 8# heavenm
过程很简单 我目前已经用xmlhttp实现了,因为他跟ie共享cookies,所以不存在提取cookies的问题.只是xmlhttp有诸多不变,想改用winhttp.
用fiddler抓包过程,无非就申请计划 判断最高佣 退出定向 生成连接 这些半天就搞定了
你也是做淘客的? 嗯啊!有什么交流的!~~~
你有转换链接的不 淘宝的我做过httponly 的COOKIE,当时弄了很多天
我发的浏览器 XIE里面好像有的
_WinINet_InternetSetCoo ...
heavenm 发表于 2016-10-1 07:52 http://www.autoitx.com/images/common/back.gif
H大,是否可以分享下这个函数呢 _WinINet_InternetSetCookie {:face (327):} 回复 7# cxlater
你好,我按照你的代码,发现取不了一号店的 ut 这个cookie,能帮我看下是为什么么
ut 在登陆后能用httpwatch 看到#include <IE.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ARRAY.AU3>
#include <WinAPI.au3>
$Form1 = GUICreate("Form1", 623, 600, 192, 114)
$ieobj = _IECreateEmbedded()
GUICtrlCreateObj($ieobj, 0, 0, 617, 393)
_IENavigate($ieobj, "https://passport.yhd.com/passport/login_input.do?")
$Ele = _IEGetObjById($ieobj,"un")
_IEFormElementSetValue($Ele,"13078480989")
$Ele = _IEGetObjById($ieobj,"pwd")
_IEFormElementSetValue($Ele,"9zuzz4yk9")
;账号:13078480989 密码:9zuzz4yk9
$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
getjson()
EndSwitch
$cookies = _IEDocGetObj($ieobj).cookie
If GUICtrlRead($Edit1) <> $cookies Then GUICtrlSetData($Edit1, $cookies)
WEnd
Func getjson()
Global $INTERNET_COOKIE_HTTPONLY = 8192 ;Requires IE 8 or higher
Global $INTERNET_COOKIE_THIRD_PARTY = 131072
Global $INTERNET_FLAG_RESTRICTED_ZONE = 16
Global $sUrl = _IEPropertyGet($ieobj ,"locationurl")
Global $sCookieName = 'ut'
Global $tSize = DllStructCreate("dword")
Global $tBuffer = DllStructCreate('char')
Global $getcookies = DllCall("wininet.dll", _
"bool", "InternetGetCookieExW", _
'wstr', $sUrl, _
'wstr', $sCookieName, _
"ptr", DllStructGetPtr($tBuffer), _
"ptr", DllStructGetPtr($tSize), _
"dword", $INTERNET_COOKIE_HTTPONLY, _
"ptr", Null _
)
If Not _WinAPI_GetLastError() Then ConsoleWrite(DllStructGetData($tBuffer, 1) & @CRLF)
ConsoleWrite(_WinAPI_GetLastError() & @CRLF)
_ArrayDisplay($getcookies)
EndFunc ;==>getjson
请问_IEDocGetObj($ieobj).cookie
获取httponly的cookie, 有解决了这个问题么
页:
[1]
2