Jump to content

IE2 - Getting Elements inside of a tag


Recommended Posts

Here is my goal, My program is automatically uploading a file to powersourceonline - a database of my company's equipment (not complete list - but most of the stuff we want to sell on powersource)

Anyway, my program is uploading a file daily. The page that comes up after the upload - has a page with a status box. I am trying to pull the text from that status box using the _IETagNameGetCollection() command

Here is a script i created to visit that site - and pull out text from a sample class - i'll change the actual class name when i get this working.

#include <IE2.au3>
#include <Inet.au3>

$ObjIE = _IECreate()

With $ObjIE
   .Visible = True
   .Navigate ("http://www.powersourceonline.com/")
EndWith

_IELoadWait($ObjIE)

$oDivs = _IETagNameGetCollection($ObjIE, "div")

For $oDiv in $oDivs
    If $oDiv.className = "container" Then
        $sMyMessage = $oDiv.innerText
        $Class = $oDiv.className
        ExitLoop
    EndIf
Next


MsgBox(0,"Testing", $sMyMessage)

This will pop up a window with the text - i want it to pop up the first (and it will be the only instance) of the text within the <div class="container"> field, (any additional html within the code will not be a problem - the purpose of getting the data is to write it to my log file

Can anyone help clean up that script so it works?

I downloaded the newest version of IE version 2 (i call it IE2.au3 for me to distinguish this from IE.au3 the original)

i am running autoit v3.1.1.122 (beta)

Link to comment
Share on other sites

Here is my goal, My program is automatically uploading a file to powersourceonline - a database of my company's equipment (not complete list - but most of the stuff we want to sell on powersource)

Anyway, my program is uploading a file daily. The page that comes up after the upload - has a page with a status box. I am trying to pull the text from that status box using the _IETagNameGetCollection() command

Here is a script i created to visit that site - and pull out text from a sample class - i'll change the actual class name when i get this working.

#include <IE2.au3>
#include <Inet.au3>

$ObjIE = _IECreate()

With $ObjIE
   .Visible = True
   .Navigate ("http://www.powersourceonline.com/")
EndWith

_IELoadWait($ObjIE)

$oDivs = _IETagNameGetCollection($ObjIE, "div")

For $oDiv in $oDivs
    If $oDiv.className = "container" Then
        $sMyMessage = $oDiv.innerText
        $Class = $oDiv.className
        ExitLoop
    EndIf
Next
MsgBox(0,"Testing", $sMyMessage)

This will pop up a window with the text - i want it to pop up the first (and it will be the only instance) of the text within the <div class="container"> field, (any additional html within the code will not be a problem - the purpose of getting the data is to write it to my log file

Can anyone help clean up that script so it works?

I downloaded the newest version of IE version 2 (i call it IE2.au3 for me to distinguish this from IE.au3 the original)

i am running autoit v3.1.1.122 (beta)

I don't see anything wrong with what you have... you can of course encounter many <div>s with the same classname and you exit when you encounter the first one... this may not be what you want to do. Also note that it is possible that the source you see with View Source is NOT eactly what is on the dynamic page... you may want to use _IEBodyReadHTML to verify.

Also, just a style point, this single line of code:

$ObjIE = _IECreate("http://www.powersourceonline.com/")oÝ÷ Ùû¥&§uìZrÙr­êeiǬjYh~Øb±«­¢+ØÀÌØí=©%ô}%
ÉÑ ¤()]¥Ñ ÀÌØí=©%(¹Y¥Í¥±ôQÉÕ(¹9Ù¥Ñ ÅÕ½Ðí¡ÑÑÀè¼½ÝÝܹÁ½ÝÉͽÕɽ¹±¥¹¹½´¼ÅÕ½Ðì¤)¹]¥Ñ ()}%1½]¥Ð ÀÌØí=©%¤

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

  • Moderators

Dale beat me to it, but this is what I had.

#include <IE2.au3>
#include <Inet.au3>

; prevent object errors from terminating your script
_IEErrorHandlerRegister()
; create a visible browser window and navigate to a webpage
$oIE = _IECreate ("http://www.powersourceonline.com/")
; get a collection object of all 'div' tags
$oDivs = _IETagNameGetCollection ($oIE, "div")
; loop through all 'div' tags
If IsObj($oDivs) Then
    For $oDiv In $oDivs
        If $oDiv.className = "container" Then
            $sMyMessage = $oDiv.innerText
            $Class = $oDiv.className
            ExitLoop
        EndIf
    Next
    MsgBox(0, "Testing", $sMyMessage)
Else
    MsgBox(48, "Error", "There were no 'div' tags found.")
EndIf
Link to comment
Share on other sites

Edit:

I don't see anything wrong with what you have... you can of course encounter many <div>s with the same classname and you exit when you encounter the first one... this may not be what you want to do. Also note that it is possible that the source you see with View Source is NOT eactly (Edit: what kind of a word was that? I have no idea what my fingers were thinking...) always what is on the dynamic page... you may want to use _IEBodyReadHTML to verify.

Edited by DaleHohm

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

  • Moderators

I just tested big daddy's version of my script

and it does the same thing as mine

is this a problem with my version of autoit or what?

Its a little hard to solve a problem when you don't know what it is.

Are you getting errors?

Is it just not giving the desired result?

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