Sign in to follow this  
Followers 0
DotoMunraitto

Need help with browser emulation?

3 posts in this topic

#1 ·  Posted (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 by DotoMunraitto

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welcome to the forums ! Posted Image

I found this example on a chinese site with referer and cookies,

hope it can help you : Posted Image

Global 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 by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Thanks man! I'll look into it once I get home... :unsure:

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0