Windows Vista Forums

How to get the content of a newly created instance of IE
  1. #1


    jason Guest

    How to get the content of a newly created instance of IE

    Hi there

    I am using vbscript to collect information from web site.

    First I created an IE object and navigated it to
    "http://www.pennyweight.com.au", I have used a function to ensure
    IE.Document.ReadyState = "complete".
    Secondly, I used codes to find the url of the "Order" link
    Thirdly, I used IE to navigate to this new order page
    Unfortunately, the content returned by the Document object is the source
    codes of page "http://www.pennyweight.com.au" instead of "Order" page. But I
    do want is the content of "Order" page.

    Hereafter are the codes I used:

    option explicit

    dim accessURL
    dim IE
    dim a

    set IE = CreateObject("InternetExplorer.Application")
    accessURL = "http://www.pennyweight.com.au"
    IE.navigate(accessURL)
    wscript.sleep 5000 ' actually I used a function to ensure
    IE.Document.ReadyState = "complete"



    for each a in IE.Document.GetElementsByTagName("a")
    if Lcase(a.innerText) = "order" then
    IE.navigate(a.href)
    wscript.sleep 5000 ' actually I used a function to ensure
    IE.Document.ReadyState = "complete"
    exit for
    end if
    Next

    wscript.echo IE.Document.GetElementsbyTagName("html")(0).innerHTML

    Can any one help me?

    Many thanks in advance!

    Jason



      My System SpecsSystem Spec

  2. #2


    Joe Fawcett Guest

    Re: How to get the content of a newly created instance of IE



    "jason" <atechmark@xxxxxx> wrote in message
    news:#mTtl9C$IHA.1152@xxxxxx

    > Hi there
    >
    > I am using vbscript to collect information from web site.
    >
    > First I created an IE object and navigated it to
    > "http://www.pennyweight.com.au", I have used a function to ensure
    > IE.Document.ReadyState = "complete".
    > Secondly, I used codes to find the url of the "Order" link
    > Thirdly, I used IE to navigate to this new order page
    > Unfortunately, the content returned by the Document object is the source
    > codes of page "http://www.pennyweight.com.au" instead of "Order" page. But
    > I do want is the content of "Order" page.
    >
    > Hereafter are the codes I used:
    >
    > option explicit
    >
    > dim accessURL
    > dim IE
    > dim a
    >
    > set IE = CreateObject("InternetExplorer.Application")
    > accessURL = "http://www.pennyweight.com.au"
    > IE.navigate(accessURL)
    > wscript.sleep 5000 ' actually I used a function to ensure
    > IE.Document.ReadyState = "complete"
    >
    > for each a in IE.Document.GetElementsByTagName("a")
    > if Lcase(a.innerText) = "order" then
    > IE.navigate(a.href)
    > wscript.sleep 5000 ' actually I used a function to ensure
    > IE.Document.ReadyState = "complete"
    > exit for
    > end if
    > Next
    >
    > wscript.echo IE.Document.GetElementsbyTagName("html")(0).innerHTML
    >
    > Can any one help me?
    >
    > Many thanks in advance!
    >
    > Jason
    >
    >
    I'd check the URL of the new page. If it's still the first URL then it maybe
    a redirection happens because of lack of a cookie, not being signed in etc.

    --

    Joe Fawcett (MVP - XML)
    http://joe.fawcett.name


      My System SpecsSystem Spec

  3. #3


    Tim Williams Guest

    Re: How to get the content of a newly created instance of IE

    If you look at the IE window (after setting it visible) what is displayed at
    the end of the code? Is it the expected page ?

    Might help to show the actual code you used (ie. include your function used
    to ensure page is fully loaded)

    Tim

    "jason" <atechmark@xxxxxx> wrote in message
    news:%23mTtl9C$IHA.1152@xxxxxx

    > Hi there
    >
    > I am using vbscript to collect information from web site.
    >
    > First I created an IE object and navigated it to
    > "http://www.pennyweight.com.au", I have used a function to ensure
    > IE.Document.ReadyState = "complete".
    > Secondly, I used codes to find the url of the "Order" link
    > Thirdly, I used IE to navigate to this new order page
    > Unfortunately, the content returned by the Document object is the source
    > codes of page "http://www.pennyweight.com.au" instead of "Order" page. But
    > I do want is the content of "Order" page.
    >
    > Hereafter are the codes I used:
    >
    > option explicit
    >
    > dim accessURL
    > dim IE
    > dim a
    >
    > set IE = CreateObject("InternetExplorer.Application")
    > accessURL = "http://www.pennyweight.com.au"
    > IE.navigate(accessURL)
    > wscript.sleep 5000 ' actually I used a function to ensure
    > IE.Document.ReadyState = "complete"
    >
    > for each a in IE.Document.GetElementsByTagName("a")
    > if Lcase(a.innerText) = "order" then
    > IE.navigate(a.href)
    > wscript.sleep 5000 ' actually I used a function to ensure
    > IE.Document.ReadyState = "complete"
    > exit for
    > end if
    > Next
    >
    > wscript.echo IE.Document.GetElementsbyTagName("html")(0).innerHTML
    >
    > Can any one help me?
    >
    > Many thanks in advance!
    >
    > Jason
    >
    >


      My System SpecsSystem Spec

  4. #4


    jason Guest

    Re: How to get the content of a newly created instance of IE

    Hi Tim,

    Thanks for your help!

    I set IE visible but the content of IE's Document was not what I wanted.
    Also I appended one more line of code IE.quit and only the IE displaying the
    content of http://www.pennyweight.com.au quit. The new IE displaying "Order"
    page is still there but seems I have no way to get its Document object.

    Attached is the whole code I used.

    ***********************************************
    option explicit

    dim accessURL
    dim IE
    dim a
    dim i
    dim txt

    set IE = CreateObject("InternetExplorer.Application")
    IE.visible = true
    accessURL = "http://www.pennyweight.com.au"

    IE.navigate(accessURL)

    'Ensure the readystate of Document is complete
    i = 0
    do until IE.ReadyState = 4
    Wscript.Sleep 100
    i = i + 1
    if i > 50 then exit do
    loop

    i = 0
    if IE.ReadyState = 4 then
    do until IE.Document.ReadyState = "complete"
    Wscript.Sleep 100
    i = i + 1
    if i > 50 then exit do
    loop
    end if

    'Get the link of order page
    for each a in IE.Document.GetElementsByTagName("a")
    if Lcase(Trim(a.innerText)) = "order" then
    txt = a.href
    exit for
    end if
    next


    IE.navigate(txt)
    i = 0
    do until IE.ReadyState = 4
    Wscript.Sleep 100
    i = i + 1
    if i > 50 then exit do
    loop

    i = 0
    if IE.ReadyState = 4 then
    do until IE.Document.ReadyState = "complete"
    Wscript.Sleep 100
    i = i + 1
    if i > 50 then exit do
    loop
    end if

    wscript.echo IE.Document.GetElementsbyTagName("html")(0).innerHTML
    IE.quit
    *********************************************************

    Best regards

    Jason



    "Tim Williams" <timjwilliams at gmail dot com> wrote in message
    news:OdDUSTE$IHA.872@xxxxxx

    > If you look at the IE window (after setting it visible) what is displayed
    > at the end of the code? Is it the expected page ?
    >
    > Might help to show the actual code you used (ie. include your function
    > used to ensure page is fully loaded)
    >
    > Tim
    >
    > "jason" <atechmark@xxxxxx> wrote in message
    > news:%23mTtl9C$IHA.1152@xxxxxx

    >> Hi there
    >>
    >> I am using vbscript to collect information from web site.
    >>
    >> First I created an IE object and navigated it to
    >> "http://www.pennyweight.com.au", I have used a function to ensure
    >> IE.Document.ReadyState = "complete".
    >> Secondly, I used codes to find the url of the "Order" link
    >> Thirdly, I used IE to navigate to this new order page
    >> Unfortunately, the content returned by the Document object is the source
    >> codes of page "http://www.pennyweight.com.au" instead of "Order" page.
    >> But I do want is the content of "Order" page.
    >>
    >> Hereafter are the codes I used:
    >>
    >> option explicit
    >>
    >> dim accessURL
    >> dim IE
    >> dim a
    >>
    >> set IE = CreateObject("InternetExplorer.Application")
    >> accessURL = "http://www.pennyweight.com.au"
    >> IE.navigate(accessURL)
    >> wscript.sleep 5000 ' actually I used a function to ensure
    >> IE.Document.ReadyState = "complete"
    >>
    >> for each a in IE.Document.GetElementsByTagName("a")
    >> if Lcase(a.innerText) = "order" then
    >> IE.navigate(a.href)
    >> wscript.sleep 5000 ' actually I used a function to ensure
    >> IE.Document.ReadyState = "complete"
    >> exit for
    >> end if
    >> Next
    >>
    >> wscript.echo IE.Document.GetElementsbyTagName("html")(0).innerHTML
    >>
    >> Can any one help me?
    >>
    >> Many thanks in advance!
    >>
    >> Jason
    >>
    >>
    >
    >


      My System SpecsSystem Spec

  5. #5


    jason Guest

    Re: How to get the content of a newly created instance of IE

    Hi Joe,

    I found the URL of the new page (http://www.pennyweight.com.au/order.html)
    is different from the original. So I don'yt think it is a redirection issue.

    Many thanks

    Jason

    "Joe Fawcett" <joefawcett@xxxxxx> wrote in message
    news:%23ZrM0SE$IHA.1180@xxxxxx

    >
    >
    > "jason" <atechmark@xxxxxx> wrote in message
    > news:#mTtl9C$IHA.1152@xxxxxx

    >> Hi there
    >>
    >> I am using vbscript to collect information from web site.
    >>
    >> First I created an IE object and navigated it to
    >> "http://www.pennyweight.com.au", I have used a function to ensure
    >> IE.Document.ReadyState = "complete".
    >> Secondly, I used codes to find the url of the "Order" link
    >> Thirdly, I used IE to navigate to this new order page
    >> Unfortunately, the content returned by the Document object is the source
    >> codes of page "http://www.pennyweight.com.au" instead of "Order" page.
    >> But I do want is the content of "Order" page.
    >>
    >> Hereafter are the codes I used:
    >>
    >> option explicit
    >>
    >> dim accessURL
    >> dim IE
    >> dim a
    >>
    >> set IE = CreateObject("InternetExplorer.Application")
    >> accessURL = "http://www.pennyweight.com.au"
    >> IE.navigate(accessURL)
    >> wscript.sleep 5000 ' actually I used a function to ensure
    >> IE.Document.ReadyState = "complete"
    >>
    >> for each a in IE.Document.GetElementsByTagName("a")
    >> if Lcase(a.innerText) = "order" then
    >> IE.navigate(a.href)
    >> wscript.sleep 5000 ' actually I used a function to ensure
    >> IE.Document.ReadyState = "complete"
    >> exit for
    >> end if
    >> Next
    >>
    >> wscript.echo IE.Document.GetElementsbyTagName("html")(0).innerHTML
    >>
    >> Can any one help me?
    >>
    >> Many thanks in advance!
    >>
    >> Jason
    >>
    >>
    > I'd check the URL of the new page. If it's still the first URL then it
    > maybe a redirection happens because of lack of a cookie, not being signed
    > in etc.
    >
    > --
    >
    > Joe Fawcett (MVP - XML)
    > http://joe.fawcett.name


      My System SpecsSystem Spec

  6. #6


    mayayana Guest

    Re: How to get the content of a newly created instance of IE

    i = 0
    do until IE.ReadyState = 4
    Wscript.Sleep 100
    i = i + 1
    if i > 50 then exit do
    loop


    I don't know whether this is the problem,
    but I don't see the point of the count to 50.
    You've designed it so that your script fails if
    the page takes more than 5 seconds to load.




      My System SpecsSystem Spec

  7. #7


    Paul Randall Guest

    Re: How to get the content of a newly created instance of IE

    Hi, Jason
    If you stick a message box statement in to pause the script before
    navigating to the order page, you can mouse around the web page and get some
    ideas of what is happening. If you hold the mouse over the order link, IE
    will show the HREF in the status bar (if you have status bar being
    displayed). It is not an ordinary HREF; it is a reference to a JScript
    routine called order. This routine pops up a new window, and displays
    http://www.pennyweight.com.au/order.html.
    Perhaps your script can be modified to extract the order.html link and
    navigate there and then play with its HTML.

    -Paul Randall

    "jason" <atechmark@xxxxxx> wrote in message
    news:OxB2rbm$IHA.3380@xxxxxx

    > Hi Tim,
    >
    > Thanks for your help!
    >
    > I set IE visible but the content of IE's Document was not what I wanted.
    > Also I appended one more line of code IE.quit and only the IE displaying
    > the content of http://www.pennyweight.com.au quit. The new IE displaying
    > "Order" page is still there but seems I have no way to get its Document
    > object.
    >
    > Attached is the whole code I used.
    >
    > ***********************************************
    > option explicit
    >
    > dim accessURL
    > dim IE
    > dim a
    > dim i
    > dim txt
    >
    > set IE = CreateObject("InternetExplorer.Application")
    > IE.visible = true
    > accessURL = "http://www.pennyweight.com.au"
    >
    > IE.navigate(accessURL)
    >
    > 'Ensure the readystate of Document is complete
    > i = 0
    > do until IE.ReadyState = 4
    > Wscript.Sleep 100
    > i = i + 1
    > if i > 50 then exit do
    > loop
    >
    > i = 0
    > if IE.ReadyState = 4 then
    > do until IE.Document.ReadyState = "complete"
    > Wscript.Sleep 100
    > i = i + 1
    > if i > 50 then exit do
    > loop
    > end if
    >
    > 'Get the link of order page
    > for each a in IE.Document.GetElementsByTagName("a")
    > if Lcase(Trim(a.innerText)) = "order" then
    > txt = a.href
    > exit for
    > end if
    > next
    >
    >
    > IE.navigate(txt)
    > i = 0
    > do until IE.ReadyState = 4
    > Wscript.Sleep 100
    > i = i + 1
    > if i > 50 then exit do
    > loop
    >
    > i = 0
    > if IE.ReadyState = 4 then
    > do until IE.Document.ReadyState = "complete"
    > Wscript.Sleep 100
    > i = i + 1
    > if i > 50 then exit do
    > loop
    > end if
    >
    > wscript.echo IE.Document.GetElementsbyTagName("html")(0).innerHTML
    > IE.quit
    > *********************************************************
    >
    > Best regards
    >
    > Jason
    >
    >
    >
    > "Tim Williams" <timjwilliams at gmail dot com> wrote in message
    > news:OdDUSTE$IHA.872@xxxxxx

    >> If you look at the IE window (after setting it visible) what is displayed
    >> at the end of the code? Is it the expected page ?
    >>
    >> Might help to show the actual code you used (ie. include your function
    >> used to ensure page is fully loaded)
    >>
    >> Tim
    >>
    >> "jason" <atechmark@xxxxxx> wrote in message
    >> news:%23mTtl9C$IHA.1152@xxxxxx

    >>> Hi there
    >>>
    >>> I am using vbscript to collect information from web site.
    >>>
    >>> First I created an IE object and navigated it to
    >>> "http://www.pennyweight.com.au", I have used a function to ensure
    >>> IE.Document.ReadyState = "complete".
    >>> Secondly, I used codes to find the url of the "Order" link
    >>> Thirdly, I used IE to navigate to this new order page
    >>> Unfortunately, the content returned by the Document object is the source
    >>> codes of page "http://www.pennyweight.com.au" instead of "Order" page.
    >>> But I do want is the content of "Order" page.
    >>>
    >>> Hereafter are the codes I used:
    >>>
    >>> option explicit
    >>>
    >>> dim accessURL
    >>> dim IE
    >>> dim a
    >>>
    >>> set IE = CreateObject("InternetExplorer.Application")
    >>> accessURL = "http://www.pennyweight.com.au"
    >>> IE.navigate(accessURL)
    >>> wscript.sleep 5000 ' actually I used a function to ensure
    >>> IE.Document.ReadyState = "complete"
    >>>
    >>> for each a in IE.Document.GetElementsByTagName("a")
    >>> if Lcase(a.innerText) = "order" then
    >>> IE.navigate(a.href)
    >>> wscript.sleep 5000 ' actually I used a function to ensure
    >>> IE.Document.ReadyState = "complete"
    >>> exit for
    >>> end if
    >>> Next
    >>>
    >>> wscript.echo IE.Document.GetElementsbyTagName("html")(0).innerHTML
    >>>
    >>> Can any one help me?
    >>>
    >>> Many thanks in advance!
    >>>
    >>> Jason
    >>>
    >>>
    >>
    >>
    >
    >


      My System SpecsSystem Spec

  8. #8


    Tim Williams Guest

    Re: How to get the content of a newly created instance of IE

    Here's a function which will return a reference to an IE window which has a
    given URL. You can use this to get a handle on the new window which opens
    on following the link.

    Tim

    Usage:
    Dim myIE
    Set myIE = GetIE("http://www.google.com")
    If not myIE is nothing then
    'do something
    End if


    'Find and return an IE window with matching URL
    'Assumes no frames.
    Function GetIE(sAddress)

    Dim objShell , objShellWindows, o
    Dim retVal, sURL


    Set retVal = Nothing
    Set objShell = CreateObject("Shell.Application")
    Set objShellWindows = objShell.Windows

    For Each o In objShellWindows
    sURL = ""
    On Error Resume Next
    sURL = o.document.Location
    On Error GoTo 0
    If sURL <> "" Then
    If ucase(Left(sURL, Len(sAddress))) = ucase(sAddress) Then
    Set retVal = o
    Exit For
    End If
    End If Next o

    Set GetIE = retVal
    End Function





    "jason" <atechmark@xxxxxx> wrote in message
    news:OxB2rbm$IHA.3380@xxxxxx

    > Hi Tim,
    >
    > Thanks for your help!
    >
    > I set IE visible but the content of IE's Document was not what I wanted.
    > Also I appended one more line of code IE.quit and only the IE displaying
    > the content of http://www.pennyweight.com.au quit. The new IE displaying
    > "Order" page is still there but seems I have no way to get its Document
    > object.
    >
    > Attached is the whole code I used.
    >
    > ***********************************************
    > option explicit
    >
    > dim accessURL
    > dim IE
    > dim a
    > dim i
    > dim txt
    >
    > set IE = CreateObject("InternetExplorer.Application")
    > IE.visible = true
    > accessURL = "http://www.pennyweight.com.au"
    >
    > IE.navigate(accessURL)
    >
    > 'Ensure the readystate of Document is complete
    > i = 0
    > do until IE.ReadyState = 4
    > Wscript.Sleep 100
    > i = i + 1
    > if i > 50 then exit do
    > loop
    >
    > i = 0
    > if IE.ReadyState = 4 then
    > do until IE.Document.ReadyState = "complete"
    > Wscript.Sleep 100
    > i = i + 1
    > if i > 50 then exit do
    > loop
    > end if
    >
    > 'Get the link of order page
    > for each a in IE.Document.GetElementsByTagName("a")
    > if Lcase(Trim(a.innerText)) = "order" then
    > txt = a.href
    > exit for
    > end if
    > next
    >
    >
    > IE.navigate(txt)
    > i = 0
    > do until IE.ReadyState = 4
    > Wscript.Sleep 100
    > i = i + 1
    > if i > 50 then exit do
    > loop
    >
    > i = 0
    > if IE.ReadyState = 4 then
    > do until IE.Document.ReadyState = "complete"
    > Wscript.Sleep 100
    > i = i + 1
    > if i > 50 then exit do
    > loop
    > end if
    >
    > wscript.echo IE.Document.GetElementsbyTagName("html")(0).innerHTML
    > IE.quit
    > *********************************************************
    >
    > Best regards
    >
    > Jason
    >
    >
    >
    > "Tim Williams" <timjwilliams at gmail dot com> wrote in message
    > news:OdDUSTE$IHA.872@xxxxxx

    >> If you look at the IE window (after setting it visible) what is displayed
    >> at the end of the code? Is it the expected page ?
    >>
    >> Might help to show the actual code you used (ie. include your function
    >> used to ensure page is fully loaded)
    >>
    >> Tim
    >>
    >> "jason" <atechmark@xxxxxx> wrote in message
    >> news:%23mTtl9C$IHA.1152@xxxxxx

    >>> Hi there
    >>>
    >>> I am using vbscript to collect information from web site.
    >>>
    >>> First I created an IE object and navigated it to
    >>> "http://www.pennyweight.com.au", I have used a function to ensure
    >>> IE.Document.ReadyState = "complete".
    >>> Secondly, I used codes to find the url of the "Order" link
    >>> Thirdly, I used IE to navigate to this new order page
    >>> Unfortunately, the content returned by the Document object is the source
    >>> codes of page "http://www.pennyweight.com.au" instead of "Order" page.
    >>> But I do want is the content of "Order" page.
    >>>
    >>> Hereafter are the codes I used:
    >>>
    >>> option explicit
    >>>
    >>> dim accessURL
    >>> dim IE
    >>> dim a
    >>>
    >>> set IE = CreateObject("InternetExplorer.Application")
    >>> accessURL = "http://www.pennyweight.com.au"
    >>> IE.navigate(accessURL)
    >>> wscript.sleep 5000 ' actually I used a function to ensure
    >>> IE.Document.ReadyState = "complete"
    >>>
    >>> for each a in IE.Document.GetElementsByTagName("a")
    >>> if Lcase(a.innerText) = "order" then
    >>> IE.navigate(a.href)
    >>> wscript.sleep 5000 ' actually I used a function to ensure
    >>> IE.Document.ReadyState = "complete"
    >>> exit for
    >>> end if
    >>> Next
    >>>
    >>> wscript.echo IE.Document.GetElementsbyTagName("html")(0).innerHTML
    >>>
    >>> Can any one help me?
    >>>
    >>> Many thanks in advance!
    >>>
    >>> Jason
    >>>
    >>>
    >>
    >>
    >
    >


      My System SpecsSystem Spec

  9. #9


    Tom Lavedas Guest

    Re: How to get the content of a newly created instance of IE

    On Aug 15, 1:23*am, "Tim Williams" <timjwilliams at gmail dot com>
    wrote:

    > Here's a function which will return a reference to an IE window which hasa
    > given URL. *You can use this to get a handle on the new window which opens
    > on following the link.
    >
    > Tim
    >
    > Usage:
    > * *Dim myIE
    > * *Set myIE = GetIE("http://www.google.com")
    > * *If not myIE is nothing then
    > * * * *'do something
    > * *End if
    >
    > 'Find and return an IE window with matching URL
    > 'Assumes no frames.
    > Function GetIE(sAddress)
    >
    > Dim objShell , objShellWindows, o
    > Dim retVal, sURL
    >
    > * * Set retVal = Nothing
    > * * Set objShell = CreateObject("Shell.Application")
    > * * Set objShellWindows = objShell.Windows
    >
    > * * For Each o In objShellWindows
    > * * * * sURL = ""
    > * * * * On Error Resume Next
    > * * * * sURL = o.document.Location
    > * * * * On Error GoTo 0
    > * * * * If sURL <> "" Then
    > * * * * * * If ucase(Left(sURL, Len(sAddress))) = ucase(sAddress) Then
    > * * * * * * * Set retVal = o
    > * * * * * * * Exit For
    > * * * * * * End If
    > * * * * End If * *Next o
    >
    > * * Set GetIE = retVal
    > End Function
    >
    > "jason" <atechm...@xxxxxx> wrote in message
    >
    > news:OxB2rbm$IHA.3380@xxxxxx
    {snip}

    > > "Tim Williams" <timjwilliams at gmail dot com> wrote in message
    > >news:OdDUSTE$IHA.872@xxxxxx

    > >> If you look at the IE window (after setting it visible) what is displayed
    > >> at the end of the code? *Is it the expected page ?
    >

    > >> Might help to show the actual code you used (ie. include your function
    > >> used to ensure page is fully loaded)
    >

    > >> Tim
    >

    > >> "jason" <atechm...@xxxxxx> wrote in message
    > >>news:%23mTtl9C$IHA.1152@xxxxxx
    > >>> Hi there
    >

    > >>> I am using vbscript to collect information from web site.
    >
    {snip}

    Tim.

    You're on the right track, but the initial problem is that the page
    that Jason is referencing does NOT follow a URL at the anchor he is
    searching for. Rather, it is accessed by a JavaScript function call.
    So, the first thing to do is use an a.click in place of the a.href/
    IE.Navigate construct of his example script.

    Also, since he doesn't get the new pages URL from the anchor, he is
    forced to search for the new window by title. Here's a function that
    finds the FIRST occurence of an IE window with a matching part of its
    title ...

    set IEW = FindWindow("How to")

    if IEW is Nothing then
    wsh.echo "Window not found"
    else
    wsh.echo left(IEW.document.body.InnerHTML, 128)
    end if

    Function FindWindow(sTitle)
    Dim wndw

    set FindWindow = Nothing
    with createobject("shell.application")
    for each wndw in .windows
    if instr(lcase(typename(wndw.document)), "htmldocument") > 0
    then
    if Instr(lcase(wndw.document.title), lcase(sTitle)) > 0 then
    set FindWindow = wndw
    exit function
    end if
    end if
    next
    end with

    end function

    HTH,

    Tom Lavedas
    ===========

      My System SpecsSystem Spec

  10. #10


    jason Guest

    Re: How to get the content of a newly created instance of IE

    Hi Tom,

    You gave me a perfect idea to solve my problem.

    Many thanks!

    Jason

    "Tom Lavedas" <tglbatch@xxxxxx> wrote in message
    news:72c24022-f9c1-4d0c-9512-5387291cdfe7@xxxxxx
    On Aug 15, 1:23 am, "Tim Williams" <timjwilliams at gmail dot com>
    wrote:

    > Here's a function which will return a reference to an IE window which has
    > a
    > given URL. You can use this to get a handle on the new window which opens
    > on following the link.
    >
    > Tim
    >
    > Usage:
    > Dim myIE
    > Set myIE = GetIE("http://www.google.com")
    > If not myIE is nothing then
    > 'do something
    > End if
    >
    > 'Find and return an IE window with matching URL
    > 'Assumes no frames.
    > Function GetIE(sAddress)
    >
    > Dim objShell , objShellWindows, o
    > Dim retVal, sURL
    >
    > Set retVal = Nothing
    > Set objShell = CreateObject("Shell.Application")
    > Set objShellWindows = objShell.Windows
    >
    > For Each o In objShellWindows
    > sURL = ""
    > On Error Resume Next
    > sURL = o.document.Location
    > On Error GoTo 0
    > If sURL <> "" Then
    > If ucase(Left(sURL, Len(sAddress))) = ucase(sAddress) Then
    > Set retVal = o
    > Exit For
    > End If
    > End If Next o
    >
    > Set GetIE = retVal
    > End Function
    >
    > "jason" <atechm...@xxxxxx> wrote in message
    >
    > news:OxB2rbm$IHA.3380@xxxxxx
    {snip}

    > > "Tim Williams" <timjwilliams at gmail dot com> wrote in message
    > >news:OdDUSTE$IHA.872@xxxxxx

    > >> If you look at the IE window (after setting it visible) what is
    > >> displayed
    > >> at the end of the code? Is it the expected page ?
    >

    > >> Might help to show the actual code you used (ie. include your function
    > >> used to ensure page is fully loaded)
    >

    > >> Tim
    >

    > >> "jason" <atechm...@xxxxxx> wrote in message
    > >>news:%23mTtl9C$IHA.1152@xxxxxx
    > >>> Hi there
    >

    > >>> I am using vbscript to collect information from web site.
    >
    {snip}

    Tim.

    You're on the right track, but the initial problem is that the page
    that Jason is referencing does NOT follow a URL at the anchor he is
    searching for. Rather, it is accessed by a JavaScript function call.
    So, the first thing to do is use an a.click in place of the a.href/
    IE.Navigate construct of his example script.

    Also, since he doesn't get the new pages URL from the anchor, he is
    forced to search for the new window by title. Here's a function that
    finds the FIRST occurence of an IE window with a matching part of its
    title ...

    set IEW = FindWindow("How to")

    if IEW is Nothing then
    wsh.echo "Window not found"
    else
    wsh.echo left(IEW.document.body.InnerHTML, 128)
    end if

    Function FindWindow(sTitle)
    Dim wndw

    set FindWindow = Nothing
    with createobject("shell.application")
    for each wndw in .windows
    if instr(lcase(typename(wndw.document)), "htmldocument") > 0
    then
    if Instr(lcase(wndw.document.title), lcase(sTitle)) > 0 then
    set FindWindow = wndw
    exit function
    end if
    end if
    next
    end with

    end function

    HTH,

    Tom Lavedas
    ===========



      My System SpecsSystem Spec

How to get the content of a newly created instance of IE problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Detect newly created computeraccounts in AD johan.m.eriksson VB Script 1 18 Sep 2008
Unable to login with newly created accounts TimT Vista account administration 2 09 Aug 2008
Newly created files protected from further access Scott R. Nelson Vista General 3 29 Jan 2008
Problem logging in with newly created user Joe Vista account administration 0 21 Dec 2007
not able to format newly created shrink volume Hari Vista installation & setup 2 14 Dec 2007