Jump to content
Sign in to follow this  

Need help with browser emulation?

Recommended Posts


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

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

$WIN32_FTYPE = "W"
$WIN32_TCHAR = "wchar"
$WIN32_TSTR = "wstr"
$WIN32_FTYPE = "A"
$WIN32_TCHAR = "char"
$WIN32_TSTR = "str"
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
Dim $BaiduCookie
$BaiduCookie = _WinINet_InternetGetCookie("http://www.baidu.com") 

While 1
    $num = Random(0,1)
    $HTMLSource = $oHTTP.Responsetext

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 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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.