Sign in to follow this  
Followers 0
royalmarine

embeded browser, get url

18 posts in this topic

#1 ·  Posted (edited)

trying to get the url of a page in an imbedded browser, but cant find it in the help file.

i can find the non embedded IE method,

$oIE = _IEAttach ("reference here")

but not for embedded :/

edit: meant to add im using this method for my embedded browser

$Browser = ObjCreate("Shell.Explorer.2")
$html = "www.google.ie" & @CR
$Browser.navigate ( $html)
Edited by royalmarine

Share this post


Link to post
Share on other sites



MsgBox(0,"",$Browser.document.url)

cheers johnone, i can see how that works.

however, my goal is for a youtube downloader.

when i navigate to a youtube url, i want my script to copy the url of the page into a label box,

and then click the "download" button beside it.

so far its working nicely when i just copy and paste the link.

how would i modify the $Browser.document.url to only set the data in the label box when there is a youtube.com url detected?

so far, this is what i have.

If $msg = $Youtube And IsObj($Browser) Then
$Browser.navigate ('http://www.youtube.com')
Sleep(500)
If $browser.document.url = "http://www.youtube.com" Then
Sleep(500)
GUICtrlSetData($_Input, $Browser.document.url)
Else
;
EndIf
EndIf

but i take it that would only work then the url = www.youtube.com and not if it contains www.youtube.com url.

Share this post


Link to post
Share on other sites

Regarding your original question, see the "embedded" parameter of _IEAttach

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

when i navigate to a youtube url, i want my script to copy the url of the page into a label box

royalmarine [or may I call you bootie?] How do you navigate to the page if you don't know what the url is?

William

Share this post


Link to post
Share on other sites

royalmarine [or may I call you bootie?] How do you navigate to the page if you don't know what the url is?

William

well... i have a button on the right for "youtube". that opens www.youtube.com

then i simply search youtube or click a link on youtube front page.

Share this post


Link to post
Share on other sites

Regarding your original question, see the "embedded" parameter of _IEAttach

Dale

hi Dale,

would it make a difference that im using shell.explorer.2 instead of IE?

Share this post


Link to post
Share on other sites

been trying to get this working with no avail.

anyone able to shed some light my way and point me in the right direction?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I really dont understand what your problem is, it has been said in this thread more than once.

From helpfile

; *******************************************************
; Example 1 - Trap COM errors so that 'Back' and 'Forward'
;               outside of history bounds does not abort script
;               (expect COM errors to be sent to the console)
; *******************************************************
;
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

_IEErrorHandlerRegister ()

$oIE = _IECreateEmbedded ()
GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 640, 460)
$GUI_LABLE = GUICtrlCreateLabel("txt", 10, 540, 500, 30)



GUISetState()       ;Show GUI

_IENavigate ($oIE, "http://www.youtube.com/watch?v=KTwwAXQOhcg")
$url = $oIE.document.url
GUICtrlSetData($GUI_LABLE,$url)
; Waiting for user to close the window
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop

    EndSelect
WEnd
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

If you want the current url to show in the label [and be available for other usage] then you might put the relevant 2 lines in the While loop as below [using Google as YouTube blocked at work here!

; *******************************************************
; Example 1 - Trap COM errors so that 'Back' and 'Forward'
;               outside of history bounds does not abort script
;               (expect COM errors to be sent to the console)
; *******************************************************
;
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

_IEErrorHandlerRegister ()

$oIE = _IECreateEmbedded ()
GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 640, 460)
$GUI_LABLE = GUICtrlCreateLabel("txt", 10, 540, 500, 30)



GUISetState()       ;Show GUI

_IENavigate ($oIE, "http://www.google.com")
$url = $oIE.document.url
GUICtrlSetData($GUI_LABLE,$url)
; Waiting for user to close the window
While 1
    $url = $oIE.document.url
GUICtrlSetData($GUI_LABLE,$url)
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop

    EndSelect
WEnd

William

Share this post


Link to post
Share on other sites

Does somebody know how to release the memory which is used by IE (embedded) when deleting the GUI but not exiting the program?

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

$oIE = 0 is not helping unfortunatelly. I assume the whole IE engine is still in memory (as threads) of autoit pid although the object is released e.g. with $oIE = 0.

Example:

;Coded by UEZ 2011 - beta version
#include <Clipboard.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

If @OSBuild < 6000 Then Exit MsgBox(16, "Error!", "Script is running properly only on Vista+ os!", 10)

Global Const $hDwmApiDll = DllOpen("dwmapi.dll")
Global $sChkAero = DllStructCreate("int;")
DllCall($hDwmApiDll, "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($sChkAero))
Global $aero = DllStructGetData($sChkAero, 1)
If Not $aero Then Exit MsgBox(16, "Error", "Aero must be enabled to grab web sites properly!", 20)
$sChkAero = 0

Global $URL, $btn, $msg, $hWnd, $input, $i
$hWnd = GUICreate("Save Web Page as an image", 320, 120)
$input = GUICtrlCreateInput("http://www.autoitscript.com/forum/", 10, 5, 300, 20)
$btn = GUICtrlCreateButton("Ok", 40, 35, 240, 70)
ControlFocus($hWnd, "", $btn)
GUISetState()
While $msg <> -3
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn
            Start()
        Case $msg = -3
            GUIDelete($hWnd)
            Exit
    EndSelect
WEnd

Func Start()
    $URL = GUICtrlRead($input)
    SplashTextOn("Screenshooting Web Site", "Please wait while taking screenshot", 300, 40, -1, -1, 1 + 2 + 4 + 32, "")
    AdlibRegister("Wait", 300)
    Web_Screenshot($URL)
    AdlibUnRegister("Wait")
    SplashOff()
    MsgBox(0, "Information", "Web Site Image copied to clipboard!", 10)
EndFunc

Func Web_Screenshot($url)
    _ReduceMemory(@AutoItPID)
    Local $oIE, $GUIActiveX, $oDocument,  $oBody, $BodyWidth, $BodyHeight
    Local $hGUI, $hWin, $aWin
    $oIE = ObjCreate("Shell.Explorer.2")

    #region render web site to get height
    $hGUI = GUICreate("",  1, 1, -1, -1, $WS_POPUP)
    $GUIActiveX = GUICtrlCreateObj ($oIE, 0, 0, 1024, 256)
    With $oIE
        .Silent = True
        .TheaterMode = False
        .FullScreen = True
        .Resizable = False
        .Navigate($URL)
        While .ReadyState <> 4
            Sleep(50)
        WEnd
    EndWith
;~  ConsoleWrite(HWnd($oIE.hwnd) & @CRLF)
    $oDocument = $oIE.document
    $oBody = $odocument.body
    $oBody.scroll = "no"
    $oBody.style.borderStyle = "none"
    $BodyWidth = $oBody.scrollWidth
    $BodyHeight = $oBody.scrollHeight

    GUIDelete($hGUI)
    #endregion

    $GUIActiveX = 0
    $hGUI = GUICreate("",  $BodyWidth,  $BodyHeight, -1, 0, BitOR($WS_CLIPCHILDREN, $WS_POPUP), Default, WinGetHandle(AutoItWinGetTitle()))
    $GUIActiveX = GUICtrlCreateObj ($oIE, 0, 0, $BodyWidth,  $BodyHeight + 50)

    With $oIE
         .Silent = True
        .TheaterMode = False
        .FullScreen = True
        .Resizable = False
        .Navigate($URL)
        While .ReadyState <> 4
            Sleep(50)
        WEnd
    EndWith

    $oDocument = $oIE.document
    $oBody =$odocument.body
    $oHtml = $odocument.documentElement
    $oBody.scroll = "no"
    $oBody.style.borderStyle = "none"
    $oHtml.style.overflow = 'hidden'

    $hWin = WinGetHandle("Program Manager")
    $aWin = WinGetPos($hWin)
    WinMove($hGUI, "", $aWin[0] - $BodyWidth + 1, $aWin[1] - $BodyHeight + 1) ;hide window
    GUISetState(@SW_SHOWNA)       ;Show GUI

    Local $hDC = _WinAPI_GetWindowDC($hGUI)
    Local $hDC_Dummy = _WinAPI_GetWindowDC(0)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Dummy)
    Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Dummy, $BodyWidth, $BodyHeight)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0,  $BodyWidth, $BodyHeight, $hDC, 0, 0, $SRCCOPY)

    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_ReleaseDC($hGUI, $hDC)
    _WinAPI_ReleaseDC(0, $hDC_Dummy)
    _WinAPI_ReleaseDC(0, $hDC)
    _ClipBoard_Open(0)
    _ClipBoard_Empty()
    _ClipBoard_SetDataEx($hBitmap, $CF_BITMAP)
    _ClipBoard_Close()
    _WinAPI_DeleteObject ($hBitmap)
    $GUIActiveX = 0
    $oIE = 0
    GUIDelete($hGUI)
EndFunc

Func Wait()
    Switch Mod($i, 4)
        Case 0
            ControlSetText("Screenshooting Web Site", "", "Static1", "Please wait while taking screenshot")
        Case 1
            ControlSetText("Screenshooting Web Site", "", "Static1", "Please wait while taking screenshot .")
        Case 2
            ControlSetText("Screenshooting Web Site", "", "Static1", "Please wait while taking screenshot ..")
        Case 3
            ControlSetText("Screenshooting Web Site", "", "Static1", "Please wait while taking screenshot ...")
    EndSwitch
    $i += 1
EndFunc

Func _ReduceMemory($ProcID = 0)
    If $ProcID = 0 or ProcessExists($ProcID) = 0 Then ; No process id specified or process doesnt exist - use current process instead.
        Local $ai_GetCurrentProcess = DllCall('kernel32.dll', 'ptr', 'GetCurrentProcess')
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'ptr', $ai_GetCurrentProcess[0])
        Return $ai_Return[0]
    EndIf
    Local $ai_Handle = DllCall("kernel32.dll", 'ptr', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $ProcID)
    Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'ptr', $ai_Handle[0])
    DllCall('kernel32.dll', 'int', 'CloseHandle', 'ptr', $ai_Handle[0])
    Return $ai_Return[0]
EndFunc

This is more or less the code I used in AutoIt Windows Screenshooter and when you take a screenshot from a web site just check the memory consumption.

I know there is a much better version from Ward available using AutoIt Objects...

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Does this help?

Remarks

_IEQuit is particularly important when creating or working with invisible instances of Internet Explorer. When AutoIt exits when working with visible instances of a browser, the browser continues to run and the visible window is left for the user to manage. When the browser instance is invisible however, when AutoIt exits the browser process is left running and there is no user interface to interact with and an orphan Iexplore.exe process is left running on the system. It is therefore good practice to call _IEQuit whenever the browser process is not needed after the script exists.

from the helpfile.

William

Edited by saywell

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Well,

when I insert

_IEQuit($GUIActiveX)
    _IEQuit($oIE)

_IEQuit($oIE) is crashing and _IEQuit($GUIActiveX) has no effect.

From help file:

_IEQuit is not allowed with embedded browser objects created with _IECreateEmbedded. The browser processes associated with those objects will close when their parent GUI window is destroyed.

Thanks for you help.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

It might, but that is saying it closes the browser object so its free when the script exits

Its $oIE.quit() that _IEQuit() uses.

I seem to remember a UDF knocking about that freed process unused memory, just cannot remember what it was called to find it.

EDIT:

Could not find the UDF, but maybe this helps

DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", -1)

MSDN says this function is in Kernel32.dll on win 7

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

@John: it is already included in the code from post#13. Look to function Func _ReduceMemory($ProcID = 0).

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

If you want the current url to show in the label [and be available for other usage] then you might put the proxy sites relevant 2 lines in the While loop as below [using Google as YouTube blocked at work here!

; *******************************************************
; Example 1 - Trap COM errors so that 'Back' and 'Forward'
;               outside of history bounds does not abort script
;               (expect COM errors to be sent to the console)
; *******************************************************
;
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

_IEErrorHandlerRegister ()

$oIE = _IECreateEmbedded ()
GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 640, 460)
$GUI_LABLE = GUICtrlCreateLabel("txt", 10, 540, 500, 30)



GUISetState()       ;Show GUI

_IENavigate ($oIE, "http://www.google.com")
$url = $oIE.document.url
GUICtrlSetData($GUI_LABLE,$url)
; Waiting for user to close the window
While 1
    $url = $oIE.document.url
GUICtrlSetData($GUI_LABLE,$url)
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop

    EndSelect
WEnd

William

hah nice script thx Edited by slucham

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