CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Access HASH returned from modules function (IE::Automation)

 



stevend1980
Novice

Jan 31, 2012, 10:40 AM

Post #1 of 6 (1304 views)
Access HASH returned from modules function (IE::Automation) Can't Post

Hi,

I'm trying to list all the links of a page using IE::Automation->getAllLinks() which returns a hash of the links on the current page.

Win32::IEAutomation::Element=HASH(0x30fee3c)

The documentation doesn't tell me what's in the hash and Data::Dumper runs out of memory trying to dump it. How do I work out what's in the hash and access the data?

Thanks


stevend1980
Novice

Jan 31, 2012, 11:17 AM

Post #2 of 6 (1297 views)
Re: [stevend1980] Access HASH returned from modules function (IE::Automation) [In reply to] Can't Post

I've got some example code and the output. Surly the links are not contained in some other layer of anonymous hash's???

How do I access these? Why would they create such a stupid data structure for a list of links?


Code
use strict; 
use warnings;
use Win32::IEAutomation;

my $ie2 = Win32::IEAutomation->new( visible => 1, warnings => 1);
$ie2->gotoURL('http://www.google.co.uk');

my @ref = $ie2->getAllLinks();

foreach (@ref) {
while ((my $key, my $value) = each(%{$_})){
print $key.", ".$value."\n";
}

}


output

Code
parent, Win32::IEAutomation=HASH(0x137c94) 
element, Win32::OLE=HASH(0x298b194)
parent, Win32::IEAutomation=HASH(0x137c94)
element, Win32::OLE=HASH(0x298b224)
parent, Win32::IEAutomation=HASH(0x137c94)
element, Win32::OLE=HASH(0x298b2b4)
parent, Win32::IEAutomation=HASH(0x137c94)
element, Win32::OLE=HASH(0x298b344)
parent, Win32::IEAutomation=HASH(0x137c94)
element, Win32::OLE=HASH(0x298b3d4)
parent, Win32::IEAutomation=HASH(0x137c94)
element, Win32::OLE=HASH(0x298b464)
parent, Win32::IEAutomation=HASH(0x137c94)
element, Win32::OLE=HASH(0x298b4f4)
parent, Win32::IEAutomation=HASH(0x137c94)
element, Win32::OLE=HASH(0x298b584)
parent, Win32::IEAutomation=HASH(0x137c94)
element, Win32::OLE=HASH(0x298b614)
parent, Win32::IEAutomation=HASH(0x137c94)
element, Win32::OLE=HASH(0x298b6a4)
parent, Win32::IEAutomation=HASH(0x137c94)
element, Win32::OLE=HASH(0x298b734)



stevend1980
Novice

Jan 31, 2012, 11:26 AM

Post #3 of 6 (1294 views)
Re: [stevend1980] Access HASH returned from modules function (IE::Automation) [In reply to] Can't Post

Here I've nested the while loop to read the hash's. Garbage and more hash refs? Am I doing something wrong or is this module broken?

Code
use strict; 
use warnings;
use Win32::IEAutomation;

my $ie2 = Win32::IEAutomation->new( visible => 1, warnings => 1);
$ie2->gotoURL('http://www.google.co.uk');

my @ref = $ie2->getAllLinks();

foreach (@ref) {
while ((my $key, my $value) = each(%{$_})){
while ((my $key2, my $value2) = each(%{$value})){
print $key2.", ".$value2."\n";
}
}
}

agent, Win32::OLE=HASH(0x32100c)
className,
id,
tagName, A
parentElement, Win32::OLE=HASH(0x28bb4cc)
onhelp,
Use of uninitialized value $value2 in concatenation (.) or string at C:/Users/Steve/eclipse/ieAuto/example.pl line 13.
onclick,
Use of uninitialized value $value2 in concatenation (.) or string at C:/Users/Steve/eclipse/ieAuto/example.pl line 13.
ondblclick,
Use of uninitialized value $value2 in concatenation (.) or string at C:/Users/Steve/eclipse/ieAuto/example.pl line 13.
onkeydown,
Use of uninitialized value $value2 in concatenation (.) or string at C:/Users/Steve/eclipse/ieAuto/example.pl line 13.
onkeyup,
Use of uninitialized value $value2 in concatenation (.) or string at C:/Users/Steve/eclipse/ieAuto/example.pl line 13.
onkeypress,
Use of uninitialized value $value2 in concatenation (.) or string at C:/Users/Steve/eclipse/ieAuto/example.pl line 13.
Use of uninitialized value $value2 in concatenation (.) or string at C:/Users/Steve/eclipse/ieAuto/example.pl line 13.
onmouseout,
onmouseover,
Use of uninitialized value $value2 in concatenation (.) or string at C:/Users/Steve/eclipse/ieAuto/example.pl line 13.
onmousemove,
Use of uninitialized value $value2 in concatenation (.) or string at C:/Users/Steve/eclipse/ieAuto/example.pl line 13.
onmousedown,
Use of uninitialized value $value2 in concatenation (.) or string at C:/Users/Steve/eclipse/ieAuto/example.pl line 13.
onmouseup,
Use of uninitialized value $value2 in concatenation (.) or string at C:/Users/Steve/eclipse/ieAuto/example.pl line 13.
document, Win32::OLE=HASH(0x28bb58c)
title,
language,
onselectstart,
Use of uninitialized value $value2 in concatenation (.) or string at C:/Users/Steve/eclipse/ieAuto/example.pl line 13.
sourceIndex, 14
recordNumber,
Use of uninitialized value $value2 in concatenation (.) or string at C:/Users/Steve/eclipse/ieAuto/example.pl line 13.
lang,
offsetLeft, -13333
offsetTop, 0
offsetWidth, 331
offsetHeight, 16
offsetParent, Win32::OLE=HASH(0x28bb63c)
innerHTML, Screen-reader users, click here to turn off Google Instant.
innerText, Screen-reader users, click here to turn off Google Instant.
outerHTML, <A style="POSITION: absolute; LEFT: -1000em" href="/setprefs?prev=http://www.google.co.uk/&amp;sig=0_yCgQm2uM5F4_34n3OOn7YfUT4h4%3D&amp;suggon=2">Screen-reader users, click here to turn off Google Instant.</A>
outerText, Screen-reader users, click here to turn off Google Instant.
parentTextEdit, Win32::OLE=HASH(0x28bb68c)
isTextEdit, 0
filters, Win32::OLE=HASH(0x28bb60c)

Code

Maybe that explains why data dumper ran out of memory


FishMonger
Veteran / Moderator

Jan 31, 2012, 12:18 PM

Post #4 of 6 (1286 views)
Re: [stevend1980] Access HASH returned from modules function (IE::Automation) [In reply to] Can't Post

Use the Data::Dumper module to inspect the data structure.
http://search.cpan.org/~smueller/Data-Dumper-2.131/Dumper.pm

For extracting the links, I'd use HTML::LinkExtor
http://search.cpan.org/~gaas/HTML-Parser-3.69/lib/HTML/LinkExtor.pm


stevend1980
Novice

Jan 31, 2012, 12:44 PM

Post #5 of 6 (1282 views)
Re: [FishMonger] Access HASH returned from modules function (IE::Automation) [In reply to] Can't Post

Hi Fishmonger,

Thanks for the reply. Data::Dumper was my first try but it just prints out of memory. There is plenty of free memory on my machine so not sure what's going on there.

I've use LinkExtor before with mechanize but the links I want to click are javascript which mechanize wont do hence trying IE::Automation.

Is their any other way to inspect the hash apart from with Data::Dumper?

Thanks


FishMonger
Veteran / Moderator

Feb 2, 2012, 6:59 AM

Post #6 of 6 (1254 views)
Re: [stevend1980] Access HASH returned from modules function (IE::Automation) [In reply to] Can't Post

How many links are you finding?

Does this give you tha same error?


Code
use strict;  
use warnings;
use Win32::IEAutomation;

my $ie2 = Win32::IEAutomation->new( visible => 0, warnings => 1);
$ie2->gotoURL('http://www.google.co.uk');

my @ref = $ie2->getAllLinks();
my $count = @ref;

print "found $count links\n\n";


EDIT: changed visible to 0 to speedup the process.


(This post was edited by FishMonger on Feb 2, 2012, 7:09 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives