Jump to content

1. Doing something in an iFrame


Recommended Posts

Hello,

i have a BIG problem.

What i want to do is:

1. Surfing to a Website with an iFrame. Wait until the page is loaded.

2. Now i try to get the Source Code from the ready-loaded-iFrame with the command _IEBodyReadHTML($iFrame), but it fails. :D The error comes also with other _IE commands, like _IEPropertyGet($iFrame, "locationurl").

Here is my script:

#include <IE.au3>

#include <File.au3>

#include <String.au3>

;;;create

$oIE = _IECreate ("http://home.arcor.de/qxggnxan/a-site-with-an-iframe.htm")

_IELoadWait ($oIE)

;;;iFrame

$iFrame0001 = _IEFrameGetObjByName ($oIE, "0001")

$sHTML = _IEBodyReadHTML ($iFrame0001)

msgbox(1,"the source code",$sHTML)

Any one can help please?

Link to comment
Share on other sites

Hello,

i have a BIG problem.

What i want to do is:

1. Surfing to a Website with an iFrame. Wait until the page is loaded.

2. Now i try to get the Source Code from the ready-loaded-iFrame with the command _IEBodyReadHTML($iFrame), but it fails. :o The error comes also with other _IE commands, like _IEPropertyGet($iFrame, "locationurl").

Here is my script:

#include <IE.au3>
#include <File.au3>
#include <String.au3>

;;;create
$oIE = _IECreate ("http://home.arcor.de/qxggnxan/a-site-with-an-iframe.htm")
_IELoadWait ($oIE)

;;;iFrame
$iFrame0001 = _IEFrameGetObjByName ($oIE, "0001")
$sHTML = _IEBodyReadHTML ($iFrame0001)
msgbox(1,"the source code",$sHTML)

Any one can help please?

You don't do any error checking to see if it got the iFrame correctly before trying to read the body. Put _IEErrorHandlerRegister() at the top of your script, and run it from SciTE so you can see the debug output to the console. Test for @error after _IEFrameGetObjByName() so you can catch problems finding the iFrame before trying to use it.

:D

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

Also, _IEGetObjByName gets you a reference to your iFrame as a tag, not as a window. You need to use _IEFrameGetObjByName

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<iframe src="http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Daps&field-keywords=text&x=7&y=18" width="820" height="220" name="0001"></iframe>

</body>

</html>

Link to comment
Share on other sites

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<iframe src="http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Daps&field-keywords=text&x=7&y=18" width="820" height="220" name="0001"></iframe>

</body>
</html>

That's a cross-site scripting situation, because the parent is in www.w3.org space and the iFrame is in www.amazon.com space. If you had added the error handler and run it in SciTE as I recommended before, you would probably see "Access Denied" or something similar.

You can extract the URL (the amazon one) from the iFrame tag and then open it in its own instance of IE, then work with that.

:D

Edit: Maybe not... I was being dense, and the "www.w3.org" is not the parent document but a standardized header, of course. This could still be a case of cross-site issues if the parent is other than www.amazon.com, but it has nothing to do with the www.w3.org part.

Edited by PsaltyDS
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

Thanks, but the htmlcode is now without www.w3.org.

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<iframe src="http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Daps&field-keywords=text&x=7&y=18" width="820" height="220" name="0001"></iframe>

</body>

</html>

i runned the script again, but the only thing i get is this empty source-code-msgbox:

Posted Image

You can extract the URL (the amazon one) from the iFrame tag and then open it in its own instance of IE, then work with that.

Whats faster & better? Open 100 IE's or run 100 iFrames? :D

I think its impossible for the current AutoIt Version to read the htmlcode from an iFrame or do some other actions with the iFrame.

thank you all

bye

Link to comment
Share on other sites

Thanks, but the htmlcode is now without www.w3.org.

i runned the script again, but the only thing i get is this empty source-code-msgbox:

Posted Image

Whats faster & better? Open 100 IE's or run 100 iFrames? :o

I think its impossible for the current AutoIt Version to read the htmlcode from an iFrame or do some other actions with the iFrame.

thank you all

bye

Did you ever try adding the error handler and running it in SciTE to see what errors might be there?

The www.w3.org part was stupidity on my part. That's just part of the header, not the parent site.

You could still have cross-site issues if the parent (whatever it is) is other than www.amazon.com. If you are creating a local html file for the parent document, then I believe www.amazon.com in a frame would be considered cross-site.

Post the errors you get in the SciTE console - they will tell the tale.

:D

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

Did you ever try adding the error handler and running it in SciTE to see what errors might be there?

I think this is what you mean, but i can't find out whats wrong.

>"C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Dokumente und Einstellungen\co1\Desktop\www.autoitscript.com\get-iframe-source-code.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams

+>09:53:14 Starting AutoIt3Wrapper v.1.9.2

>Running AU3Check (1.54.13.0) from:C:\Program Files\AutoIt3

+>09:53:15 AU3Check ended.rc:0

>Running:(3.2.12.1):C:\Program Files\AutoIt3\autoit3.exe "C:\Dokumente und Einstellungen\co1\Desktop\www.autoitscript.com\get-iframe-source-code.au3"

--> COM Error Encountered in get-iframe-source-code.au3

----> $IEComErrorScriptline = 2210

----> $IEComErrorNumberHex = 80020009

----> $IEComErrorNumber = -2147352567

----> $IEComErrorWinDescription = Zugriff verweigert (access denied)

----> $IEComErrorDescription = Zugriff verweigert (access denied)

----> $IEComErrorSource =

----> $IEComErrorHelpFile = C:\WINDOWS\system32\mshtml.hlp

----> $IEComErrorHelpContext = 0

----> $IEComErrorLastDllError = 0

+>09:53:32 AutoIT3.exe ended.rc:0

+>09:53:33 AutoIt3Wrapper Finished

>Exit code: 0 Time: 18.827

Edited by iloveautoitv3
Link to comment
Share on other sites

How about with some nice highlighting?!

----> $IEComErrorWinDescription = Zugriff verweigert (access denied)

----> $IEComErrorDescription = Zugriff verweigert (access denied)

hmm, i dont know how to fix this problem...

changed the <title>what the fuck</title>

added <meta name="description" content="what the fuck"/>

added to the iframe tags ... title="0001" ... longdesc="0001"

:o

i think i give up with this html-iframe-getting-the-source-thing. Now i gaved the embedded-thing a try and it woooooooooooorks !! :D

#include <GUIConstants.au3>

#include <IE.au3>

_IEErrorHandlerRegister ()

$iframe0001 = _IECreateEmbedded ()

GUICreate("Embedded Web control Test", 640, 580, _

(@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _

$WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$guiiframe0001 = GUICtrlCreateObj($iframe0001, 10, 40, 100, 100)

GUISetState()

_IENavigate ($iframe0001, "http://www.google.com")

_IELoadWait ($guiiframe0001)

$heyy0001 = _IEBodyReadHTML ($iframe0001)

msgbox(1,"source1",$heyy0001)

thank u all

bye

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