Jump to content

IE8 Get URL


Casey
 Share

Recommended Posts

Hello,

I have looked through the posts and examples and I will admit that I am stumbling. I have a task in front of me to generate a list of URLs that are considered business critical since recent JRE6 updates have created havoc amongst our end-users.

What I have in mind is a script that the end-user can execute after they have opened all the URLs that they deem critical which will parse all open instances of iexplore.exe reading all tabs and get the URLs and write them to a text file. They can then email in the txt file so I can build a list of sites to review Java requirements prior to pushing out new updates. I could then exclude certain systems from SCCM collections based on those findings.

This is the first time that I feel utterly confused as to which direction I need to take to get to the completed script in the shortest amount of time. Is there anyone will to share an example or who can clue me in. The examples for _IEAttach seems to expect a better understanding of things than I have. 4eyes recent post looked promising but confusing.

Thank you,

Casey

Link to comment
Share on other sites

This script writes the URL of the leftmost tab to a textfile, closes the tab, and continues until the iexplore process is killed by closing the last tab.

#include <IE.au3>

opt ("WinTitleMatchMode" , 2)


for $i = 1 to 1 step 0

$oIE = _IEAttach ("Internet Explorer" , "WindowTitle")

If @error = $_IEStatus_NoMatch Then
    msgbox (0, '' , "internet explorer instance closed")
    exitloop
else

    WinActivate ("Internet Explorer")
Winwaitactive ("Internet Explorer")

$addr = _IEPropertyGet ($oIE, "locationURL")
If Not ProcessExists ("iexplore.exe") Then exitloop
filewrite ("c:\testurls.txt" , $addr & @CRLF & @CRLF)
send ("^w")
sleep (500)
Endif

Next


run ("notepad c:\testurls.txt")
exit
Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Thank you for getting me started. I looked at what you provided and made a little adaptation since I can't close the tabs because the end-users may have open forms that they are filling out. Ideally I would like for the user to see no change in their desktop; even something as little as making one page active when another originally was would generate many calls that the helpdesk folks don't need.

Here is the modified version that makes use of some pieces from examples in the help file.

I see 2 immediate problems. First, it will log the URL from any open iexplore.exe process if there is only 1 tab. If there is more than one tab it will not pull the URL from the first tab even though it is able to retrieve the handle. Second, if I could understand the first it might give a clue to how to get the URLs from the other tabs.

#include <IE.au3>

$var = WinList()

For $i = 1 To $var[0][0]
    ; Only display visble windows that have a title
    If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
        ;MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1])
        $oIE = _IEAttach($var[$i][1], "HWND")
        If @error = $_IEStatus_NoMatch Then
            ;MsgBox(0,"","No Match Line 12")
            $file = FileOpen("c:\testurls.txt", 1)
            FileWrite($file, $var[$i][1] & @CRLF & @CRLF)
            FileWrite($file, $var[$i][0] & @CRLF & @CRLF)
            FileWrite($file, "____________________________________________________________" & @CRLF & @CRLF)
            FileClose($file)
        Else
            $addr = _IEPropertyGet($oIE, "locationURL")
            $file = FileOpen("c:\testurls.txt", 1)
            FileWrite($file, $var[$i][1] & @CRLF & @CRLF)
            FileWrite($file, $var[$i][0] & @CRLF & @CRLF)
            FileWrite($file, $addr & @CRLF & @CRLF)
            FileWrite($file, "____________________________________________________________" & @CRLF & @CRLF)
            FileClose($file)
            Sleep(500)
        EndIf
        ;ExitLoop
    Else
    EndIf
Next

Run("notepad c:\testurls.txt")

Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf

EndFunc   ;==>IsVisible
Link to comment
Share on other sites

Start with Example 5 for _IEAttach and simply change the line

$aIE[$i] = $oIE

to

$aIE[$i] = _IEPropertyGet($oIE, "locationurl")

You will then have an array of URLs for all IE instances.

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

Link to comment
Share on other sites

iamtheky and Dale,

Thanks for the assistance. There were a couple of posts that I stumbled upon last night that, along with your guidance, pretty much got me where I wanted to go. The code I am posting is rough and isn't quite there but I know what I need to do. Below you will find my last test where I was making sure I got the array right since I don't use that option much. I didn't and don't need an array for what i am after but it helped me understand some anomalies that I was seeing. For some reason in my early testing what I wrote ended up making IE flaky. When I would use the window info tool it would actually crash the tab I moused over and IE would then regenerate it. Anyway I wanted to post before someone else took the time.

Thanks again,

Casey

Edit:Spell Check

#include <IE.au3>
#include <file.au3>
#include <Array.au3>

Dim $aRecords, $Result
Global $aRecords[1]
$aRecords[0] = "JPM"
_FileReadToArray("c:\testurls.txt", $aRecords)
    
$i = 0
While $i <= 100000000 ; I put this here for testing opening new windows since I initially had problems reading tabs
    ProcessWait("iexplore.exe")
    If ProcessExists("iexplore.exe") Then
        IE_connect()
    EndIf
    $i = $i + 1
WEnd
;******************************
;Where log file Exists which I created manually for this test
;Run("notepad c:\testurls.txt")
;******************************
Func IE_connect()
    Dim $ObjShell = ObjCreate("Shell.Application")
    Dim $ObjShellWindows = $ObjShell.Windows(); collection of all ShellWindows (IE and File Explorer)
    Dim $ObjIE

    For $Window In $ObjShellWindows
        If StringInStr($window.LocationURL, "http:") > 0 Or StringInStr($window.LocationURL, "https:") > 0 Or StringInStr($window.LocationURL, "ftp:") > 0 Then
            $iKeyIndex = _ArrayBinarySearch($aRecords, $window.LocationURL)
            If $iKeyIndex <> -1 Then
            ElseIf $iKeyIndex = -1 Then
                $file = FileOpen("c:\testurls.txt", 1)
                FileWrite($file, $window.LocationURL & @CRLF)
                FileClose($file)
                _ArrayAdd($aRecords, $window.LocationURL)
                _ArraySort($aRecords)
                ;_ArrayDisplay($aRecords, "Array After Add")
            EndIf
            Sleep(500)
        EndIf
    Next
EndFunc   ;==>IE_connect
Edited by Casey
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...