Jump to content
Sign in to follow this  
homemade

IEAttach not working?

Recommended Posts

homemade

I have a script to pull data from a certain website.

Problem is it only works when I use IECreate instead of IEAttach.

Creating a new IE every time I want to run the script is not possible because of the complicated multiple logins and search criteria to get to the page that has the data I need.

Anything I can do to fix this?

Share this post


Link to post
Share on other sites
Juvigy

You will have to give more details. I would guess that you dont use IEAttach right.

Share this post


Link to post
Share on other sites
homemade

I'm at work right now so I don't have the code with me but it went something like this:

I used IEattach and then tried to read either the bodyhtml or textread(forgot which one exactly) to extract a certain string.

It worked fine with IEcreate but doesn't work with IEattach.

I had an open instance of IE and tried to mess around with how IEattach reads the title name but that didn't help.

Share this post


Link to post
Share on other sites
DaleHohm

I used IEattach and then tried to read either the bodyhtml or textread(forgot which one exactly) to extract a certain string.

It worked fine with IEcreate but doesn't work with IEattach.

It is not clear what you mean worked with _IECreate that doesn't work with _IEAttach.

My guess is thht you are being foiled by frames. Use _IEBodyReadText in the browser after an _IECreate and examine what it contains to see for certain. Also suggest using DebugBar.

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

Share this post


Link to post
Share on other sites
homemade

What I mean is that I initially used IECreate with the code but now I'm opting to use IEAttach because it's more practical in my situation.

Share this post


Link to post
Share on other sites
DaleHohm

Sorry, read my last post and provide a useful answer and you may get more help.

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

Share this post


Link to post
Share on other sites
homemade

Dale, I followed what you suggested and I'm getting a values of 0.

The problem isn't getting the data I need it's attaching to IE correctly which only seems to work with IECreate.

Edited by homemade

Share this post


Link to post
Share on other sites
DaleHohm

Use a lot more words to describe what you are doing, what you expect to happen and what happens instead. Post code and annotate it with your observations and questions. You are not providing nearly enough to help you.

Example:

Dale, I followed what you suggested and I'm getting a values of 0.

What are you talking about exactly? Show code. Provide a reproducer.

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

Share this post


Link to post
Share on other sites
homemade

Here's my code:

#include <String.au3>
#include <ClipBoard.au3>
#include <IE.au3>
#include <Excel.au3>
$oIE = _IEAttach ("C:\Users\Dude\Desktop\New Text document.html - Windows Internet Explorer") ;Attach to open instance of IE. This is a saved page of the website I intend to work with.
$sHTML = _IEBodyReadText($oIE) ;Read the contents of the current website
MsgBox(0, "Document Source", $oIE) ;Display the results from the what was read.

$sListing = StringRegExpReplace($sHTML,".*(Listing Agent:.*)Agent Phone: .*","\1 \2") ;Extract a certain string from the body of text from the webpage.
$sShort = StringReplace($sListing, "Listing Agent: ", "") ;Clean up the string
$nametrim = StringTrimRight ($sShort, 11 )  ;More string cleaning
$sEmail = StringRegExpReplace($sHTML,".*(Email: .*)Fax: .*","\1") ;Extract another part of the body of text from the webpage.
$sMail = StringReplace($sEmail, "Email: ", "") ;More string cleaning

$eMailclip = _ClipBoard_SetData ($sMail) ;Place the first cleaned string in the clipboard

WinActivate("Microsoft Excel - Book1  [Compatibility Mode]", "") ;Switch over to excel to paste the first string
Send("^{END}")
Send("{DOWN}")
Send("^v")
Sleep (100)
_ClipBoard_Empty()
$nameclip = _ClipBoard_SetData ($nametrim) ;Place the second cleaned string in the clipboard
Send("{LEFT}")
Send("^v") ;Paste the second cleaned string into excel
Sleep (100)
_ClipBoard_Empty()

What I want to do is attach to an open window of IE, read the contents of the page, and extract 2 pieces of data(Agent Name and Email), then paste the 2 variables into excel in adjacent cells.

I need to go through thousands of pages to extract data. Every single page is the same format so the only thing different is the data.

It is not feasible for me to use IECreate because the website that I'm working with has multiple secured logins with a physical authenticator key.

I initially wrote the code using IECreate and it was able to do exactly what I wanted.

When I switched to IEAttach, the value that I'm get from _IEBodyReadText is now 0 instead of the huge string that I'd normally get when using IECreate.

I have saved a copy of the webpage source if that helps.

http://docs.google.com/Doc?docid=0ATIqDtgIYbCnZGN3aGcyNnRfNWR0eGpyNGM1&hl=en

Share this post


Link to post
Share on other sites
Authenticity

Seems like it's an instance comparison problem, the last example code of _IEAttach() demonstrates how to walk the internet explorer instances, you can get the title of this array of object and compare it yourself. Another alternative is to use "hwnd" option:

Opt("WinTextMatchMode", 2)
#include <IE.au3>

$hWnd = WinGetHandle("C:\Users\Dude\Desktop\New Text document.html - Windows Internet Explorer")
$oIE = _IEAttach($hWnd, "hwnd")

..and in case there is a capitalizing syntax, try this:

#include <IE.au3>

$hWnd = WinGetHandle("[REGEXPTITLE:(?i)\QC:\Users\Dude\Desktop\New Text document.html - Windows Internet Explorer\E]")
$oIE = _IEAttach($hWnd, "hwnd")

Share this post


Link to post
Share on other sites
homemade

Your solution worked Authenticity. Thanks for the help everybody.

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.