Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - REQ: internetexplorer com object and access to array of links

Reply
 
Old 04-28-2008   #1 (permalink)
Robertico


 
 

REQ: internetexplorer com object and access to array of links

I use the next script to extract all links from a website:

param($url = $(throw "Please specify a URL"))
$ie=new-object -com internetexplorer.application;
$ie.navigate2($url);
while ($ie.busy) {sleep -milliseconds 50}
$links=@($ie.document.getElementsByTagName("A"));
$links | select href
$ie.quit();

It displays all links ....but i need access to each separate link in $links.

So i tried this:
ForEach ($link in $links)
{#Do myThing}

But it returns : "System.__ComObject" instead of a link.

IMO $links is a array of links, so way can't access the separate links ?

Please help


Thanks in advance,

Robertico



My System SpecsSystem Spec
Old 04-28-2008   #2 (permalink)
Shay Levi


 
 

Re: REQ: internetexplorer com object and access to array of links


Hi Robertico,


Try to select the properties you need first and then access the array:


PS 55> $ie=new-object -com internetexplorer.application
PS 56> $ie.visible=$true
PS 57> $ie.navigate2("www.google.com")
PS 58> while ($ie.busy) {sleep -milliseconds 50}
PS 59> $links=@($ie.document.getElementsByTagName("A")) | select href,innerText
PS 60> $ie.quit()
PS 61>
PS 61> $links

href innerText
---- ---------
http://images.google.co.il/imghp?hl=en&tab=wi Images
http://news.google.co.il/nwshp?hl=en&tab=wn News
http://groups.google.co.il/grphp?hl=en&tab=wg Groups
http://scholar.google.com/schhp?hl=en&tab=ws Scholar
http://mail.google.com/mail/?hl=en&tab=wm Gmail
http://www.google.co.il/intl/en/options/ more ?
http://www.google.com/calendar/render?hl=en&tab=wc Calendar
http://docs.google.com/?hl=en&tab=wo Documents
http://www.google.co.il/intl/en/options/ even
more »
https://www.google.com/accounts/Logi...//www.google.c... Sign in
http://www.google.co.il/advanced_search?hl=en Advanced
Search
http://www.google.co.il/preferences?hl=en Preferences
http://www.google.co.il/language_tools?hl=en Language
Tools
http://www.google.co.il/setprefs?sig...E6FxggehvupU4k... ?????
http://www.google.co.il/intl/en/ads/ Advertising
Program
http://www.google.co.il/intl/en/about.html About
Google
http://www.google.com/ncr Go
to Google.com


PS 62> $links.length
17

# get the first link
PS 63> $links[0]

href innerText
---- ---------
http://images.google.co.il/imghp?hl=en&tab=wi Images


# get the last link
PS 64> $links[-1]

href innerText
---- ---------
http://www.google.com/ncr Go
to Google.com

Go to Google.com





-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> I use the next script to extract all links from a website:
>
> param($url = $(throw "Please specify a URL"))
> $ie=new-object -com internetexplorer.application;
> $ie.navigate2($url);
> while ($ie.busy) {sleep -milliseconds 50}
> $links=@($ie.document.getElementsByTagName("A"));
> $links | select href
> $ie.quit();
> It displays all links ....but i need access to each separate link in
> $links.
>
> So i tried this:
> ForEach ($link in $links)
> {#Do myThing}
> But it returns : "System.__ComObject" instead of a link.
>
> IMO $links is a array of links, so way can't access the separate links
> ?
>
> Please help
>
> Thanks in advance,
>
> Robertico
>

My System SpecsSystem Spec
Old 04-29-2008   #3 (permalink)
Robertico


 
 

Re: REQ: internetexplorer com object and access to array of links

IShay,

'll tested it.
(I only need the links, so i deleted the innerText from the selection)

the variable $links in your example displays all the links (as expected)
$links[0] displays: @{href=http://images.google.nl/imghp?hl=nl&tab=wi}

So, why displays $links all the links without @{href= } and $links[0]
with @{href= }

Robertico


"Shay Levi" <no@xxxxxx> wrote in message
news:8766a944292af8ca7756466a7250@xxxxxx
Quote:

>
> Hi Robertico,
>
>
> Try to select the properties you need first and then access the array:
>
>
> PS 55> $ie=new-object -com internetexplorer.application
> PS 56> $ie.visible=$true
> PS 57> $ie.navigate2("www.google.com")
> PS 58> while ($ie.busy) {sleep -milliseconds 50}
> PS 59> $links=@($ie.document.getElementsByTagName("A")) | select
> href,innerText
> PS 60> $ie.quit()
> PS 61>
> PS 61> $links
>
> href
> innerText
> ---- ---------
> http://images.google.co.il/imghp?hl=en&tab=wi
> Images
> http://news.google.co.il/nwshp?hl=en&tab=wn News
> http://groups.google.co.il/grphp?hl=en&tab=wg
> Groups
> http://scholar.google.com/schhp?hl=en&tab=ws
> Scholar
> http://mail.google.com/mail/?hl=en&tab=wm
> Gmail
> http://www.google.co.il/intl/en/options/ more
> ?
> http://www.google.com/calendar/render?hl=en&tab=wc
> Calendar
> http://docs.google.com/?hl=en&tab=wo
> Documents
> http://www.google.co.il/intl/en/options/ even
> more »
> https://www.google.com/accounts/Logi...//www.google.c... Sign
> in
> http://www.google.co.il/advanced_search?hl=en
> Advanced Search
> http://www.google.co.il/preferences?hl=en
> Preferences
> http://www.google.co.il/language_tools?hl=en
> Language Tools
> http://www.google.co.il/setprefs?sig...E6FxggehvupU4k...
> ?????
> http://www.google.co.il/intl/en/ads/
> Advertising Program
> http://www.google.co.il/intl/en/about.html
> About Google
> http://www.google.com/ncr Go
> to Google.com
>
>
> PS 62> $links.length
> 17
>
> # get the first link
> PS 63> $links[0]
>
> href
> innerText
> ---- ---------
> http://images.google.co.il/imghp?hl=en&tab=wi
> Images
>
>
> # get the last link
> PS 64> $links[-1]
>
> href
> innerText
> ---- ---------
> http://www.google.com/ncr Go
> to Google.com
>
> Go to Google.com
>
>
>
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

>> I use the next script to extract all links from a website:
>>
>> param($url = $(throw "Please specify a URL"))
>> $ie=new-object -com internetexplorer.application;
>> $ie.navigate2($url);
>> while ($ie.busy) {sleep -milliseconds 50}
>> $links=@($ie.document.getElementsByTagName("A"));
>> $links | select href
>> $ie.quit();
>> It displays all links ....but i need access to each separate link in
>> $links.
>>
>> So i tried this:
>> ForEach ($link in $links)
>> {#Do myThing}
>> But it returns : "System.__ComObject" instead of a link.
>>
>> IMO $links is a array of links, so way can't access the separate links
>> ?
>>
>> Please help
>>
>> Thanks in advance,
>>
>> Robertico
>>
>
>

My System SpecsSystem Spec
Old 04-30-2008   #4 (permalink)
Shay Levi


 
 

Re: REQ: internetexplorer com object and access to array of links



Hi

I'm not sure I follow you. If I execute $links[0] (deleted the innerText)
I get:


PS 29> $links[0]

href
----
http://images.google.co.il/imghp?hl=en&tab=wi


PS 30> $links[0].href
http://images.google.co.il/imghp?hl=en&tab=wi



Nothing like this:

@{href=http://images.google.nl/imghp?hl=nl&tab=wi}



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> IShay,
>
> 'll tested it.
> (I only need the links, so i deleted the innerText from the selection)
> the variable $links in your example displays all the links (as
> expected) $links[0] displays:
> @{href=http://images.google.nl/imghp?hl=nl&tab=wi}
>
> So, why displays $links all the links without @{href= } and
> $links[0] with @{href= }
>
> Robertico
>
> "Shay Levi" <no@xxxxxx> wrote in message
> news:8766a944292af8ca7756466a7250@xxxxxx
>
Quote:

>> Hi Robertico,
>>
>> Try to select the properties you need first and then access the
>> array:
>>
>> PS 55> $ie=new-object -com internetexplorer.application
>> PS 56> $ie.visible=$true
>> PS 57> $ie.navigate2("www.google.com")
>> PS 58> while ($ie.busy) {sleep -milliseconds 50}
>> PS 59> $links=@($ie.document.getElementsByTagName("A")) | select
>> href,innerText
>> PS 60> $ie.quit()
>> PS 61>
>> PS 61> $links
>> href
>> innerText
>> ----
>> ---------
>> http://images.google.co.il/imghp?hl=en&tab=wi
>> Images
>> http://news.google.co.il/nwshp?hl=en&tab=wn
>> News
>> http://groups.google.co.il/grphp?hl=en&tab=wg
>> Groups
>> http://scholar.google.com/schhp?hl=en&tab=ws
>> Scholar
>> http://mail.google.com/mail/?hl=en&tab=wm
>> Gmail
>> http://www.google.co.il/intl/en/options/
>> more
>> ?
>> http://www.google.com/calendar/render?hl=en&tab=wc
>> Calendar
>> http://docs.google.com/?hl=en&tab=wo
>> Documents
>> http://www.google.co.il/intl/en/options/
>> even
>> more »
>> https://www.google.com/accounts/Logi...//www.google.c...
>> Sign
>> in
>> http://www.google.co.il/advanced_search?hl=en
>> Advanced Search
>> http://www.google.co.il/preferences?hl=en
>> Preferences
>> http://www.google.co.il/language_tools?hl=en
>> Language Tools
>> http://www.google.co.il/setprefs?sig...E6FxggehvupU4k...
>> ?????
>> http://www.google.co.il/intl/en/ads/
>> Advertising Program
>> http://www.google.co.il/intl/en/about.html
>> About Google
>> http://www.google.com/ncr
>> Go
>> to Google.com
>> PS 62> $links.length
>> 17
>> # get the first link
>> PS 63> $links[0]
>> href
>> innerText
>> ----
>> ---------
>> http://images.google.co.il/imghp?hl=en&tab=wi
>> Images
>> # get the last link
>> PS 64> $links[-1]
>> href
>> innerText
>> ----
>> ---------
>> http://www.google.com/ncr
>> Go
>> to Google.com
>> Go to Google.com
>>
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> I use the next script to extract all links from a website:
>>>
>>> param($url = $(throw "Please specify a URL"))
>>> $ie=new-object -com internetexplorer.application;
>>> $ie.navigate2($url);
>>> while ($ie.busy) {sleep -milliseconds 50}
>>> $links=@($ie.document.getElementsByTagName("A"));
>>> $links | select href
>>> $ie.quit();
>>> It displays all links ....but i need access to each separate link in
>>> $links.
>>> So i tried this:
>>> ForEach ($link in $links)
>>> {#Do myThing}
>>> But it returns : "System.__ComObject" instead of a link.
>>> IMO $links is a array of links, so way can't access the separate
>>> links ?
>>>
>>> Please help
>>>
>>> Thanks in advance,
>>>
>>> Robertico
>>>

My System SpecsSystem Spec
Old 04-30-2008   #5 (permalink)
Robertico


 
 

Re: REQ: internetexplorer com object and access to array of links

The complete script:

$url=www.google.com
$ie=new-object -com internetexplorer.application;
$ie.navigate2($url);
while ($ie.busy) {sleep -milliseconds 50}
$links=@($ie.document.getElementsByTagName("A"))| select href
$ie.quit();
Write-Host $links[0]

Screendump:


Command line


PowerGUI

Robertico


"Shay Levi" <no@xxxxxx> wrote in message news:8766a944297f48ca78c8322783be@xxxxxx
Quote:

>
>
> Hi
>
> I'm not sure I follow you. If I execute $links[0] (deleted the innerText)
> I get:
>
>
> PS 29> $links[0]
>
> href
> ----
> http://images.google.co.il/imghp?hl=en&tab=wi
>
>
> PS 30> $links[0].href
> http://images.google.co.il/imghp?hl=en&tab=wi
>
>
>
> Nothing like this:
>
> @{href=http://images.google.nl/imghp?hl=nl&tab=wi}
>
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

>> IShay,
>>
>> 'll tested it.
>> (I only need the links, so i deleted the innerText from the selection)
>> the variable $links in your example displays all the links (as
>> expected) $links[0] displays:
>> @{href=http://images.google.nl/imghp?hl=nl&tab=wi}
>>
>> So, why displays $links all the links without @{href= } and
>> $links[0] with @{href= }
>>
>> Robertico
>>
>> "Shay Levi" <no@xxxxxx> wrote in message
>> news:8766a944292af8ca7756466a7250@xxxxxx
>>
Quote:

>>> Hi Robertico,
>>>
>>> Try to select the properties you need first and then access the
>>> array:
>>>
>>> PS 55> $ie=new-object -com internetexplorer.application
>>> PS 56> $ie.visible=$true
>>> PS 57> $ie.navigate2("www.google.com")
>>> PS 58> while ($ie.busy) {sleep -milliseconds 50}
>>> PS 59> $links=@($ie.document.getElementsByTagName("A")) | select
>>> href,innerText
>>> PS 60> $ie.quit()
>>> PS 61>
>>> PS 61> $links
>>> href
>>> innerText
>>> ----
>>> ---------
>>> http://images.google.co.il/imghp?hl=en&tab=wi
>>> Images
>>> http://news.google.co.il/nwshp?hl=en&tab=wn
>>> News
>>> http://groups.google.co.il/grphp?hl=en&tab=wg
>>> Groups
>>> http://scholar.google.com/schhp?hl=en&tab=ws
>>> Scholar
>>> http://mail.google.com/mail/?hl=en&tab=wm
>>> Gmail
>>> http://www.google.co.il/intl/en/options/
>>> more
>>> ?
>>> http://www.google.com/calendar/render?hl=en&tab=wc
>>> Calendar
>>> http://docs.google.com/?hl=en&tab=wo
>>> Documents
>>> http://www.google.co.il/intl/en/options/
>>> even
>>> more »
>>> https://www.google.com/accounts/Logi...//www.google.c...
>>> Sign
>>> in
>>> http://www.google.co.il/advanced_search?hl=en
>>> Advanced Search
>>> http://www.google.co.il/preferences?hl=en
>>> Preferences
>>> http://www.google.co.il/language_tools?hl=en
>>> Language Tools
>>> http://www.google.co.il/setprefs?sig...E6FxggehvupU4k...
>>> ?????
>>> http://www.google.co.il/intl/en/ads/
>>> Advertising Program
>>> http://www.google.co.il/intl/en/about.html
>>> About Google
>>> http://www.google.com/ncr
>>> Go
>>> to Google.com
>>> PS 62> $links.length
>>> 17
>>> # get the first link
>>> PS 63> $links[0]
>>> href
>>> innerText
>>> ----
>>> ---------
>>> http://images.google.co.il/imghp?hl=en&tab=wi
>>> Images
>>> # get the last link
>>> PS 64> $links[-1]
>>> href
>>> innerText
>>> ----
>>> ---------
>>> http://www.google.com/ncr
>>> Go
>>> to Google.com
>>> Go to Google.com
>>>
>>> -----
>>> Shay Levi
>>> $cript Fanatic
>>> http://scriptolog.blogspot.com
>>>> I use the next script to extract all links from a website:
>>>>
>>>> param($url = $(throw "Please specify a URL"))
>>>> $ie=new-object -com internetexplorer.application;
>>>> $ie.navigate2($url);
>>>> while ($ie.busy) {sleep -milliseconds 50}
>>>> $links=@($ie.document.getElementsByTagName("A"));
>>>> $links | select href
>>>> $ie.quit();
>>>> It displays all links ....but i need access to each separate link in
>>>> $links.
>>>> So i tried this:
>>>> ForEach ($link in $links)
>>>> {#Do myThing}
>>>> But it returns : "System.__ComObject" instead of a link.
>>>> IMO $links is a array of links, so way can't access the separate
>>>> links ?
>>>>
>>>> Please help
>>>>
>>>> Thanks in advance,
>>>>
>>>> Robertico
>>>>
>
>
My System SpecsSystem Spec
Old 04-30-2008   #6 (permalink)
Robertico


 
 

Re: REQ: internetexplorer com object and access to array of links

In addition.

I'am using Powershell v.1.0

Robertico


"Shay Levi" <no@xxxxxx> wrote in message
news:8766a944297f48ca78c8322783be@xxxxxx
Quote:

>
>
> Hi
>
> I'm not sure I follow you. If I execute $links[0] (deleted the innerText)
> I get:
>
>
> PS 29> $links[0]
>
> href
> ----
> http://images.google.co.il/imghp?hl=en&tab=wi
>
>
> PS 30> $links[0].href
> http://images.google.co.il/imghp?hl=en&tab=wi
>
>
>
> Nothing like this:
>
> @{href=http://images.google.nl/imghp?hl=nl&tab=wi}
>
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

>> IShay,
>>
>> 'll tested it.
>> (I only need the links, so i deleted the innerText from the selection)
>> the variable $links in your example displays all the links (as
>> expected) $links[0] displays:
>> @{href=http://images.google.nl/imghp?hl=nl&tab=wi}
>>
>> So, why displays $links all the links without @{href= } and
>> $links[0] with @{href= }
>>
>> Robertico
>>
>> "Shay Levi" <no@xxxxxx> wrote in message
>> news:8766a944292af8ca7756466a7250@xxxxxx
>>
Quote:

>>> Hi Robertico,
>>>
>>> Try to select the properties you need first and then access the
>>> array:
>>>
>>> PS 55> $ie=new-object -com internetexplorer.application
>>> PS 56> $ie.visible=$true
>>> PS 57> $ie.navigate2("www.google.com")
>>> PS 58> while ($ie.busy) {sleep -milliseconds 50}
>>> PS 59> $links=@($ie.document.getElementsByTagName("A")) | select
>>> href,innerText
>>> PS 60> $ie.quit()
>>> PS 61>
>>> PS 61> $links
>>> href
>>> innerText
>>> ----
>>> ---------
>>> http://images.google.co.il/imghp?hl=en&tab=wi
>>> Images
>>> http://news.google.co.il/nwshp?hl=en&tab=wn
>>> News
>>> http://groups.google.co.il/grphp?hl=en&tab=wg
>>> Groups
>>> http://scholar.google.com/schhp?hl=en&tab=ws
>>> Scholar
>>> http://mail.google.com/mail/?hl=en&tab=wm
>>> Gmail
>>> http://www.google.co.il/intl/en/options/
>>> more
>>> ?
>>> http://www.google.com/calendar/render?hl=en&tab=wc
>>> Calendar
>>> http://docs.google.com/?hl=en&tab=wo
>>> Documents
>>> http://www.google.co.il/intl/en/options/
>>> even
>>> more »
>>> https://www.google.com/accounts/Logi...//www.google.c...
>>> Sign
>>> in
>>> http://www.google.co.il/advanced_search?hl=en
>>> Advanced Search
>>> http://www.google.co.il/preferences?hl=en
>>> Preferences
>>> http://www.google.co.il/language_tools?hl=en
>>> Language Tools
>>> http://www.google.co.il/setprefs?sig...E6FxggehvupU4k...
>>> ?????
>>> http://www.google.co.il/intl/en/ads/
>>> Advertising Program
>>> http://www.google.co.il/intl/en/about.html
>>> About Google
>>> http://www.google.com/ncr
>>> Go
>>> to Google.com
>>> PS 62> $links.length
>>> 17
>>> # get the first link
>>> PS 63> $links[0]
>>> href
>>> innerText
>>> ----
>>> ---------
>>> http://images.google.co.il/imghp?hl=en&tab=wi
>>> Images
>>> # get the last link
>>> PS 64> $links[-1]
>>> href
>>> innerText
>>> ----
>>> ---------
>>> http://www.google.com/ncr
>>> Go
>>> to Google.com
>>> Go to Google.com
>>>
>>> -----
>>> Shay Levi
>>> $cript Fanatic
>>> http://scriptolog.blogspot.com
>>>> I use the next script to extract all links from a website:
>>>>
>>>> param($url = $(throw "Please specify a URL"))
>>>> $ie=new-object -com internetexplorer.application;
>>>> $ie.navigate2($url);
>>>> while ($ie.busy) {sleep -milliseconds 50}
>>>> $links=@($ie.document.getElementsByTagName("A"));
>>>> $links | select href
>>>> $ie.quit();
>>>> It displays all links ....but i need access to each separate link in
>>>> $links.
>>>> So i tried this:
>>>> ForEach ($link in $links)
>>>> {#Do myThing}
>>>> But it returns : "System.__ComObject" instead of a link.
>>>> IMO $links is a array of links, so way can't access the separate
>>>> links ?
>>>>
>>>> Please help
>>>>
>>>> Thanks in advance,
>>>>
>>>> Robertico
>>>>
>
>

My System SpecsSystem Spec
Old 04-30-2008   #7 (permalink)
Shay Levi


 
 

Re: REQ: internetexplorer com object and access to array of links


I guess that's the reason, I'm using v2. I don't see it as a problem but
If you want $links[0] to look like a plain string then replace select with
foreach:


PS > $links=@($ie.document.getElementsByTagName("A"))| % {$_.href}
PS > $links[0]

http://images.google.co.il/imghp?hl=iw&tab=wi

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> In addition.
>
> I'am using Powershell v.1.0
>
> Robertico
>
> "Shay Levi" <no@xxxxxx> wrote in message
> news:8766a944297f48ca78c8322783be@xxxxxx
>
Quote:

>> Hi
>>
>> I'm not sure I follow you. If I execute $links[0] (deleted the
>> innerText) I get:
>>
>> PS 29> $links[0]
>>
>> href
>> ----
>> http://images.google.co.il/imghp?hl=en&tab=wi
>> PS 30> $links[0].href
>> http://images.google.co.il/imghp?hl=en&tab=wi
>> Nothing like this:
>>
>> @{href=http://images.google.nl/imghp?hl=nl&tab=wi}
>>
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> IShay,
>>>
>>> 'll tested it.
>>> (I only need the links, so i deleted the innerText from the
>>> selection)
>>> the variable $links in your example displays all the links (as
>>> expected) $links[0] displays:
>>> @{href=http://images.google.nl/imghp?hl=nl&tab=wi}
>>> So, why displays $links all the links without @{href= } and
>>> $links[0] with @{href= }
>>>
>>> Robertico
>>>
>>> "Shay Levi" <no@xxxxxx> wrote in message
>>> news:8766a944292af8ca7756466a7250@xxxxxx
>>>> Hi Robertico,
>>>>
>>>> Try to select the properties you need first and then access the
>>>> array:
>>>>
>>>> PS 55> $ie=new-object -com internetexplorer.application
>>>> PS 56> $ie.visible=$true
>>>> PS 57> $ie.navigate2("www.google.com")
>>>> PS 58> while ($ie.busy) {sleep -milliseconds 50}
>>>> PS 59> $links=@($ie.document.getElementsByTagName("A")) | select
>>>> href,innerText
>>>> PS 60> $ie.quit()
>>>> PS 61>
>>>> PS 61> $links
>>>> href
>>>> innerText
>>>> ----
>>>> ---------
>>>> http://images.google.co.il/imghp?hl=en&tab=wi
>>>> Images
>>>> http://news.google.co.il/nwshp?hl=en&tab=wn
>>>> News
>>>> http://groups.google.co.il/grphp?hl=en&tab=wg
>>>> Groups
>>>> http://scholar.google.com/schhp?hl=en&tab=ws
>>>> Scholar
>>>> http://mail.google.com/mail/?hl=en&tab=wm
>>>> Gmail
>>>> http://www.google.co.il/intl/en/options/
>>>> more
>>>> ?
>>>> http://www.google.com/calendar/render?hl=en&tab=wc
>>>> Calendar
>>>> http://docs.google.com/?hl=en&tab=wo
>>>> Documents
>>>> http://www.google.co.il/intl/en/options/
>>>> even
>>>> more »
>>>> https://www.google.com/accounts/Logi...//www.google.c.
>>>> ..
>>>> Sign
>>>> in
>>>> http://www.google.co.il/advanced_search?hl=en
>>>> Advanced Search
>>>> http://www.google.co.il/preferences?hl=en
>>>> Preferences
>>>> http://www.google.co.il/language_tools?hl=en
>>>> Language Tools
>>>> http://www.google.co.il/setprefs?sig...E6FxggehvupU4k.
>>>> ..
>>>> ?????
>>>> http://www.google.co.il/intl/en/ads/
>>>> Advertising Program
>>>> http://www.google.co.il/intl/en/about.html
>>>> About Google
>>>> http://www.google.com/ncr
>>>> Go
>>>> to Google.com
>>>> PS 62> $links.length
>>>> 17
>>>> # get the first link
>>>> PS 63> $links[0]
>>>> href
>>>> innerText
>>>> ----
>>>> ---------
>>>> http://images.google.co.il/imghp?hl=en&tab=wi
>>>> Images
>>>> # get the last link
>>>> PS 64> $links[-1]
>>>> href
>>>> innerText
>>>> ----
>>>> ---------
>>>> http://www.google.com/ncr
>>>> Go
>>>> to Google.com
>>>> Go to Google.com
>>>> -----
>>>> Shay Levi
>>>> $cript Fanatic
>>>> http://scriptolog.blogspot.com
>>>>> I use the next script to extract all links from a website:
>>>>>
>>>>> param($url = $(throw "Please specify a URL"))
>>>>> $ie=new-object -com internetexplorer.application;
>>>>> $ie.navigate2($url);
>>>>> while ($ie.busy) {sleep -milliseconds 50}
>>>>> $links=@($ie.document.getElementsByTagName("A"));
>>>>> $links | select href
>>>>> $ie.quit();
>>>>> It displays all links ....but i need access to each separate link
>>>>> in
>>>>> $links.
>>>>> So i tried this:
>>>>> ForEach ($link in $links)
>>>>> {#Do myThing}
>>>>> But it returns : "System.__ComObject" instead of a link.
>>>>> IMO $links is a array of links, so way can't access the separate
>>>>> links ?
>>>>> Please help
>>>>>
>>>>> Thanks in advance,
>>>>>
>>>>> Robertico
>>>>>

My System SpecsSystem Spec
Old 05-01-2008   #8 (permalink)
Robertico


 
 

Re: REQ: internetexplorer com object and access to array of links

Shay,

Thanks !

$links=@($ie.document.getElementsByTagName("A"))| % {$_.href} did the trick
!!

BTW i upgraded to version 2 CTP

Robertico


"Shay Levi" <no@xxxxxx> wrote in message
news:8766a9442996e8ca792d568fa15e@xxxxxx
Quote:

>
> I guess that's the reason, I'm using v2. I don't see it as a problem but
> If you want $links[0] to look like a plain string then replace select with
> foreach:
>
>
> PS > $links=@($ie.document.getElementsByTagName("A"))| % {$_.href}
> PS > $links[0]
>
> http://images.google.co.il/imghp?hl=iw&tab=wi
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

>> In addition.
>>
>> I'am using Powershell v.1.0
>>
>> Robertico
>>
>> "Shay Levi" <no@xxxxxx> wrote in message
>> news:8766a944297f48ca78c8322783be@xxxxxx
>>
Quote:

>>> Hi
>>>
>>> I'm not sure I follow you. If I execute $links[0] (deleted the
>>> innerText) I get:
>>>
>>> PS 29> $links[0]
>>>
>>> href
>>> ----
>>> http://images.google.co.il/imghp?hl=en&tab=wi
>>> PS 30> $links[0].href
>>> http://images.google.co.il/imghp?hl=en&tab=wi
>>> Nothing like this:
>>>
>>> @{href=http://images.google.nl/imghp?hl=nl&tab=wi}
>>>
>>> -----
>>> Shay Levi
>>> $cript Fanatic
>>> http://scriptolog.blogspot.com
>>>> IShay,
>>>>
>>>> 'll tested it.
>>>> (I only need the links, so i deleted the innerText from the
>>>> selection)
>>>> the variable $links in your example displays all the links (as
>>>> expected) $links[0] displays:
>>>> @{href=http://images.google.nl/imghp?hl=nl&tab=wi}
>>>> So, why displays $links all the links without @{href= } and
>>>> $links[0] with @{href= }
>>>>
>>>> Robertico
>>>>
>>>> "Shay Levi" <no@xxxxxx> wrote in message
>>>> news:8766a944292af8ca7756466a7250@xxxxxx
>>>>> Hi Robertico,
>>>>>
>>>>> Try to select the properties you need first and then access the
>>>>> array:
>>>>>
>>>>> PS 55> $ie=new-object -com internetexplorer.application
>>>>> PS 56> $ie.visible=$true
>>>>> PS 57> $ie.navigate2("www.google.com")
>>>>> PS 58> while ($ie.busy) {sleep -milliseconds 50}
>>>>> PS 59> $links=@($ie.document.getElementsByTagName("A")) | select
>>>>> href,innerText
>>>>> PS 60> $ie.quit()
>>>>> PS 61>
>>>>> PS 61> $links
>>>>> href
>>>>> innerText
>>>>> ----
>>>>> ---------
>>>>> http://images.google.co.il/imghp?hl=en&tab=wi
>>>>> Images
>>>>> http://news.google.co.il/nwshp?hl=en&tab=wn
>>>>> News
>>>>> http://groups.google.co.il/grphp?hl=en&tab=wg
>>>>> Groups
>>>>> http://scholar.google.com/schhp?hl=en&tab=ws
>>>>> Scholar
>>>>> http://mail.google.com/mail/?hl=en&tab=wm
>>>>> Gmail
>>>>> http://www.google.co.il/intl/en/options/
>>>>> more
>>>>> ?
>>>>> http://www.google.com/calendar/render?hl=en&tab=wc
>>>>> Calendar
>>>>> http://docs.google.com/?hl=en&tab=wo
>>>>> Documents
>>>>> http://www.google.co.il/intl/en/options/
>>>>> even
>>>>> more »
>>>>> https://www.google.com/accounts/Logi...//www.google.c.
>>>>> ..
>>>>> Sign
>>>>> in
>>>>> http://www.google.co.il/advanced_search?hl=en
>>>>> Advanced Search
>>>>> http://www.google.co.il/preferences?hl=en
>>>>> Preferences
>>>>> http://www.google.co.il/language_tools?hl=en
>>>>> Language Tools
>>>>> http://www.google.co.il/setprefs?sig...E6FxggehvupU4k.
>>>>> ..
>>>>> ?????
>>>>> http://www.google.co.il/intl/en/ads/
>>>>> Advertising Program
>>>>> http://www.google.co.il/intl/en/about.html
>>>>> About Google
>>>>> http://www.google.com/ncr
>>>>> Go
>>>>> to Google.com
>>>>> PS 62> $links.length
>>>>> 17
>>>>> # get the first link
>>>>> PS 63> $links[0]
>>>>> href
>>>>> innerText
>>>>> ----
>>>>> ---------
>>>>> http://images.google.co.il/imghp?hl=en&tab=wi
>>>>> Images
>>>>> # get the last link
>>>>> PS 64> $links[-1]
>>>>> href
>>>>> innerText
>>>>> ----
>>>>> ---------
>>>>> http://www.google.com/ncr
>>>>> Go
>>>>> to Google.com
>>>>> Go to Google.com
>>>>> -----
>>>>> Shay Levi
>>>>> $cript Fanatic
>>>>> http://scriptolog.blogspot.com
>>>>>> I use the next script to extract all links from a website:
>>>>>>
>>>>>> param($url = $(throw "Please specify a URL"))
>>>>>> $ie=new-object -com internetexplorer.application;
>>>>>> $ie.navigate2($url);
>>>>>> while ($ie.busy) {sleep -milliseconds 50}
>>>>>> $links=@($ie.document.getElementsByTagName("A"));
>>>>>> $links | select href
>>>>>> $ie.quit();
>>>>>> It displays all links ....but i need access to each separate link
>>>>>> in
>>>>>> $links.
>>>>>> So i tried this:
>>>>>> ForEach ($link in $links)
>>>>>> {#Do myThing}
>>>>>> But it returns : "System.__ComObject" instead of a link.
>>>>>> IMO $links is a array of links, so way can't access the separate
>>>>>> links ?
>>>>>> Please help
>>>>>>
>>>>>> Thanks in advance,
>>>>>>
>>>>>> Robertico
>>>>>>
>
>

My System SpecsSystem Spec
Old 05-21-2008   #9 (permalink)
Oana


 
 

Oana

ciau




My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
InternetExplorer Com Object Find Utility PowerShell
Give focus to an InternetExplorer.Application object VB Script
Re: InternetExplorer.Application COM object. PowerShell
InternetExplorer.Application COM object. PowerShell
new-object -com internetexplorer.application PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46