Jump to content

Help with IE.au3 and frames please


Recommended Posts

I need to be able to read info from a webpage with frames. I have tried many methods with the built in _IE functions but I cannot seem to access any of the data from inside a frame. Here is an example frame, how would I pull text from any of the span elements.

Example:
<iframe ...blah blah>
    <html>
        <body>
            <div class="calItem">
                <span id="user"></span>
                <span id="event"></span>
                <span id="loc"></span>
                <span id="time"></span>
                <span id="info"></span>
            </div>
        </body>
    </html>
</iframe>
Link to comment
Share on other sites

If you are trying to extract information from a notepad environment like the above example then you will have more luck using the File commands like Read Line and so on...

no I just wrote that up from memory of approximately what the html looked like when viewed in firebug. Obviously there is more to the page but I'm not looking at the page from my work, that is just the iframe part. I'm helping a friend for his work. Basically I need to pull calendar events from an online website, and use a script to compare that information to scheduling availability of employees, and auto assign certain people to certain events in a database, and add it to their outlook calendar as well.

First thing first though is to pull information from the website, it just happens though that I've never needed to do this with data in a frame and it's giving me trouble.

Link to comment
Share on other sites

Not sure on the extact answer but I give you a start.

Once you get the div data you can use a loop to more through and get the data. There are additional libraries in the example script section that deal with this.

#include <IE.au3>

$oIE = _IECreate("Ur URL") ; creates a new IE windo and navs there
$oDiv = _IETagNameGetCollection($oIE, "div", 0) ; get a handle to the div
_IELoadWait($oDiv)
$divData = _IETagNameGetCollection($oIE, "alItem")

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Hello,

If you know the name of the frame then this will work.

#include <ie.au3>

$oIE = _IECreate("http://www.htmlcodetutorial.com/frames/frameset.html")

$frameA = _IEFrameGetObjByName($oIE, "framea") ; this is the name of the frame contained inside the name="framea"
$frameB = _IEFrameGetObjByName($oIE, "frameb") ; this is the name of the frame contained inside the name="frameb"
$frameC = _IEFrameGetObjByName($oIE, "framec") ; this is the name of the frame contained inside the name="framec"

ConsoleWrite(_IEBodyReadText($frameA)); outputs page text from frameA

otherwise you can do this:

#include <ie.au3>

$oIE = _IECreate("http://www.htmlcodetutorial.com/frames/frameset.html")

$frames = _IEFrameGetCollection($oIE);
$numFrames = @extended ; number of frames

For $i = 0 to ($numFrames -1)
    $oFrame = _IEFrameGetCollection($oIE, $i)
    ConsoleWrite(_IEBodyReadText($oFrame)
Next

Please next time look at the AutoIt helpfile, it has many many useful examples which all work. A little common sense allows you to alter the code to suit your needs, its all there for a reason.

AFAIK this forum is to assist people not write whole chunks of code for them on request.

Rant over

Steve

EDIT: its way to early for coding, hense the rant. Sorry, however my comments still stand so i wont remove it.

Edited by Steveiwonder

They call me MrRegExpMan

Link to comment
Share on other sites

Note that if the frame contains content from a different site, XSS (cross-site scripting) security will prevent you from getting in via the DOM. You can verify that by adding _IEErrorHandlerRegister() to the top and running it from SciTE. You will see ACCESS DENIED errors in the console.

:idea:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Note that if the frame contains content from a different site, XSS (cross-site scripting) security will prevent you from getting in via the DOM. You can verify that by adding _IEErrorHandlerRegister() to the top and running it from SciTE. You will see ACCESS DENIED errors in the console.

:idea:

That might be my problem. I'll check because the frame is always found in autoit, but never seems to have anything in it.

Edit: Had an idea, if its not possible for me to get the data because of XSS, is there any API for the new developer tools built into IE8 that would allow me to pull html from it? Because it displays all the html inside the iframe too, just like firebug for firefox.

@Steveiwonder

Before I posted I DID read the help file and try to get the frame by name, I didn't try the collection thing because I was successfully getting the frame but any action I performed on that object errored. I found that this was because the object I was getting was empty.

I too am an advocate of reading the wonderfully useful help file 1st as well as not asking people to write scripts. I mean look at some of my other post, not to many but they are 90% me helping others. I can do every other part of the script I talked about on my own, I just needed help with the iframe because the examples didn't seem to work for me.

Edited by ShawnW
Link to comment
Share on other sites

Did you manage to get what you wanted to work?

I dont see why you would be getting an error, and if try and explain what your attempting to get.

I suggest you post the code your using, the errors your getting and then someone on this forum can tell you where your going wrong, thats my point.

What you were asking is for someone to write the code for you, its all about learning from your mistakes. If you dont show your mistakes we cannot help you learn.

They call me MrRegExpMan

Link to comment
Share on other sites

Not working but what I tried was something like this. (ommited the site and login info)

#include <ie.au3>
$oIE = _IECreate()

$oFrame = _IEFrameGetObjByName($oIE,"panel2")
If @error Then
    ConsoleWrite("_IEFrameGetObjByName - Error Code: "&@error&@CRLF)
Else
    ConsoleWrite("_IEFrameGetObjByName - Success!!!"&@CRLF)
EndIf

$oUser = _IEGetObjById($oFrame,"user")
If @error Then
    ConsoleWrite("_IEGetObjById - Error Code: "&@error&@CRLF)
Else
    ConsoleWrite("_IEGetObjById - Success!!!"&@CRLF)
EndIf

$user = _IEPropertyGet($oUser,"innertext")
If @error Then
    ConsoleWrite("_IEPropertyGet - Error Code: "&@error&@CRLF)
Else
    ConsoleWrite("_IEPropertyGet - Success!!!"&@CRLF)
EndIf

The resulting console messages are as follows.

_IEFrameGetObjByName - Success!!!

C:\Program Files\AutoIt3\Include\ie.au3 (2382) : ==> The requested action with this object has failed.:

If IsObj($o_object.document.getElementById($s_Id)) Then

If IsObj($o_object.document^ ERROR

Link to comment
Share on other sites

Please add _IEErrorHandlerRegister() to your code as PsaltyDS suggested.

Dale

Edit: BTW, if you do see an Access is Denied XSS error, you can open the URL of the frame in a new window with _IECreate()

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

Please add _IEErrorHandlerRegister() to your code as PsaltyDS suggested.

Dale

Edit: BTW, if you do see an Access is Denied XSS error, you can open the URL of the frame in a new window with _IECreate()

I do see access denied errors.

When I put the url of the frame into _IECreate it redirects me somewhere else when i try and access it directly.

@Steveiwonder

User is just who entered the event, not really important to my problem.

I'm not giving the url because some google bot will find it, and I'm not risking someone seeing this when they google the website or company, since my friend was not really supposed to give me his login info to make and test this. Besides you would not be able to get in to see the page without logging in either.

Edited by ShawnW
Link to comment
Share on other sites

If it is a server-side redirect, there is not much you can do. It it is a client-side redirect you may be able to abort it before it goes to the new location (you'd need to inject javascript into the page and abort the onunload event).

You can read more about the XSS security in the link in my sig.

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

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