DotoMunraitto Posted April 15, 2011 Share Posted April 15, 2011 (edited) Hi guys, I'm kinda new here. I want to ask how I'd go about doing browser emulation with AutoIt? If you aren't familiar with the term browser emulation, I believe it's one where you emulate a browser environment while interacting with a website. So far, I'm aware that AutoIt has the HttpSetUserAgent function which I can use to set the User-Agent header but how do I set other headers? Like the Referer, Cookie, etc? Edited April 15, 2011 by DotoMunraitto Link to comment Share on other sites More sharing options...
wakillon Posted April 15, 2011 Share Posted April 15, 2011 (edited) Welcome to the forums ! I found this example on a chinese site with referer and cookies, hope it can help you : expandcollapse popupGlobal Const $AU3_VERSION = StringSplit(@AutoItVersion, ".") Global Const $AU3_UNICODE = Number($AU3_VERSION[2] & "." & $AU3_VERSION[3]) >= 2.13 Global $WIN32_FTYPE, $WIN32_TCHAR, $WIN32_TSTR If $AU3_UNICODE Then $WIN32_FTYPE = "W" $WIN32_TCHAR = "wchar" $WIN32_TSTR = "wstr" Else $WIN32_FTYPE = "A" $WIN32_TCHAR = "char" $WIN32_TSTR = "str" EndIf $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") Dim $BaiduCookie $BaiduCookie = _WinINet_InternetGetCookie("http://www.baidu.com") While 1 $num = Random(0,1) $oHTTP.Open("GET","http://act.hi.baidu.com/pet/3e01bbc3beb34f6e4c696e65cde2b9d22105/eat?t="&$num) $oHTTP.setRequestHeader("Referer","http://hi.baidu.com/iokey") $oHTTP.setRequestHeader("Cookie",$BaiduCookie) $oHTTP.Send() $HTMLSource = $oHTTP.Responsetext TrayTip("????",$HTMLSource,10) Sleep(3000) WEnd Func _WinINet_InternetGetCookie($sUrl, $iBufferSize = 2048) Local $tSize = DllStructCreate("dword") DllStructSetData($tSize, 1, $iBufferSize) Local $tCookieData = DllStructCreate($WIN32_TCHAR & "[" & $iBufferSize & "]") Local $avResult = DllCall("wininet.dll", "int", "InternetGetCookie" & $WIN32_FTYPE, $WIN32_TSTR, $sUrl, "ptr", 0, "ptr", DllStructGetPtr($tCookieData), "ptr", DllStructGetPtr($tSize)) If @error Then Return SetError(1, 0, "") If Not $avResult[0] Then Return SetError(1, DllStructGetData($tSize, 1), "") Return DllStructGetData($tCookieData, 1) EndFunc ;==>_WinINet_InternetGetCookie Edited April 15, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
DotoMunraitto Posted April 15, 2011 Author Share Posted April 15, 2011 Thanks man! I'll look into it once I get home... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now