Jump to content

Using _IELinkGetCollection and getting an error


Recommended Posts

I am trying to use _IELinkGetCollection to get the links from this page http://www.wfan.com/pages/podcast/801.rss but I am getting this error:

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

SetExtended($o_object.document.links.length)

SetExtended($o_object.document.links^ ERROR

not sure what that means but is there a way around this

This is the test script I was using:

; *******************************************************
; Example 1 - Open browser with basic example, get link collection,
;               loop through items and display the associated link URL references
; *******************************************************
;
#include <IE.au3>
$oIE = _IECreate ( "http://www.wfan.com/pages/podcast/801.rss", 0, 1, 0)
$oLinks = _IELinkGetCollection ($oIE)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found")
For $oLink In $oLinks
    MsgBox(0, "Link Info", $oLink.href)
Next
Link to comment
Share on other sites

Unfortunately, the page you are referencing is not an HTML page, but rather an XML document rendered with CSS (feedUI.css). It therefore is not seen as a browser window and does not have an IE DOM that IE.au3 can parse.

I believe that to get what you are looking for, you must read and parse the XML directly.

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

I am trying to use _IELinkGetCollection to get the links from this page http://www.wfan.com/pages/podcast/801.rss but I am getting this error:

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

SetExtended($o_object.document.links.length)

SetExtended($o_object.document.links^ ERROR

not sure what that means but is there a way around this

This is the test script I was using:

; *******************************************************
; Example 1 - Open browser with basic example, get link collection,
;               loop through items and display the associated link URL references
; *******************************************************
;
#include <IE.au3>
$oIE = _IECreate ( "http://www.wfan.com/pages/podcast/801.rss", 0, 1, 0)
$oLinks = _IELinkGetCollection ($oIE)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found")
For $oLink In $oLinks
    MsgBox(0, "Link Info", $oLink.href)
Next
Using a post from: http://www.autoitscript.com/forum/index.ph...8340&hl=XML here is a nice way to see all the links on the page.

#include <guiconstants.au3>
$form = GuiCreate("Links", 800, 600)
$list = GUICtrlCreateList("", 0, 0, 799, 599)
GUISetState(@SW_SHOW)

Dim $objHTTP
Dim $objReturn
Dim $Result
Dim $packageQueryUrl= "http://www.wfan.com/pages/podcast/801.rss"

$objHTTP = ObjCreate("Microsoft.XMLHTTP")
;$objReturn = ObjCreate("Msxml2.DOMdocument.3.0")

$objHTTP.Open("Get", $packageQueryUrl, False )
$objHTTP.Send

$Result = $objHTTP.ResponseText

$nOffset = 1
while 1
    $links = stringregexp($Result, '(?i)(?s)(?:.*?)\<link>(.*?)</link>', 1, $nOffset)
    if @error = 0 Then
        $nOffset = @extended
    Else
        ExitLoop
    EndIf
    for $i = 0 to UBound($links) - 1
        $out = StringRegExpReplace($links[$i], '\s', '', 1)
        guictrlsetdata($list, $out)
    Next
WEnd

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

side note, since that page lists podcasts with the 'podcast' included in the link, you can also get quite specific. Just replace the while/wend loop with:

while 1
    $links = stringregexp($Result, '(?i)(?s)(?:.*?)<link>(.*?)</link>', 1, $nOffset)
    if @error = 0 Then
        $nOffset = @extended
    Else
        ExitLoop
    EndIf
    for $i = 0 to UBound($links) - 1
        $out = StringRegExpReplace($links[$i], '\s', '', 1)
        if NOT StringInStr($out, "podcast", 0) Then
        Else
            guictrlsetdata($list, $out)
        EndIf
    Next
WEnd

You don't have to output it to a list box either, you can throw them into an array; you can output them to a media player and play one by one, whatever you want to do.

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Thanks for the help!

Yeah I want to download the first 5 or so mp3s to my computer from a few different places. I also would like to grab the text description of each podcast but I think from what you showed me so far I should be able to work that out.

Link to comment
Share on other sites

Thanks for the help!

Yeah I want to download the first 5 or so mp3s to my computer from a few different places. I also would like to grab the text description of each podcast but I think from what you showed me so far I should be able to work that out.

Yep,

Should be fairly simple, just count 5 and exit the loop after that; and you can pull link descriptios by either a) doing another loop or :D nesting another stringregex inside of there to pull text :D. YOu can use INETGET to get the mp3's and put them wherever you want :)

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

I have been playing around with this but I can't get InetGet to download the .mp3 for me. This is what I got so far:

Dim $objHTTP
Dim $objReturn
Dim $Result
Dim $packageQueryUrl= "http://www.wfan.com/pages/podcast/801.rss"

$objHTTP = ObjCreate("Microsoft.XMLHTTP")


$objHTTP.Open("Get", $packageQueryUrl, False )
$objHTTP.Send

$Result = $objHTTP.ResponseText

$nOffset = 0
$a = 0
while $a <= 6
    $a = $a + 1
    $links = StringRegExp ( $Result, '(?i)(?s)(?:.*?)<link>(.*?)</link>', 1, $nOffset)
;$links = StringRegExp ( $Result, '(?i)(?s)(?:.*?)<link>(.*?)</link>', 1, $nOffset )
    if @error = 0 Then
        $nOffset = @extended
    Else
        ExitLoop
    EndIf
    for $i = 0 to UBound($links) - 1
        $out = StringRegExpReplace($links[$i], '\s', '', 1)
        if NOT StringInStr($out, ".mp3", 0) Then
        Else
            InetGet ( $links[0], "C:\Documents and Settings\Administrator\My Documents\Downloads\temp\Mike&maddog3.mp3", 0, 0  )
            ConsoleWrite ($links[0])
        EndIf
    Next
WEnd

When I write $links to the console I noticed that I am getting a bunch of spaces before the link address to the .mp3 and I think that is messing with InetGet. I think I need to change the pattern a bit for the StringRegExp but everything I try either returns the links still with the spaces or nothing at all.

Any ideas?

Link to comment
Share on other sites

I have been playing around with this but I can't get InetGet to download the .mp3 for me. This is what I got so far:

Here you go: Removes lines spaces in the link, checks if download file exists, if not, creates it, downloads the file (now with a progress bar) and writes the information to the console.

Dim $objHTTP
Dim $objReturn
Dim $Result
Dim $packageQueryUrl = "http://www.wfan.com/pages/podcast/801.rss"
$objHTTP = ObjCreate("Microsoft.XMLHTTP")
$objHTTP.Open("Get", $packageQueryUrl, False)
$objHTTP.Send
$Result = $objHTTP.ResponseText

$nOffset = 0
$a = 0
While $a <= 6
    $a = $a + 1
    $links = StringRegExp($Result, '(?i)(?s)(?:.*?)<link>(.*?)</link>', 1, $nOffset)
    If @error = 0 Then
        $nOffset = @extended
    Else
        ExitLoop
    EndIf
    For $i = 0 To UBound($links) - 1
        $out = StringRegExpReplace($links[$i], '\s', '', 1)
        If Not StringInStr($out, ".mp3", 0) Then
        Else
            $get = $links[0]
            $get = StringRegExpReplace($get, '\s', '')
            $name = StringRegExp($get, '(?i)(?s)(?:.*)/(.*?).mp3', 1)
                If Not FileExists(@MyDocumentsDir&"\Downloads\temp\") Then DirCreate(@MyDocumentsDir&"\Downloads\temp\")
            ConsoleWrite("MP3 Link: " & $get & @CRLF & "MP3 Name: " & $name[0] & ".mp3" & @CRLF)
            InetGet($get, @MyDocumentsDir & "\Downloads\temp\" & $name[0] & ".mp3", 0, 1)
                ProgressOn("Download Manager", "Downloading: " & $name[0] & ".mp3")
                    $size = InetGetSize($get)
                        While @InetGetActive
                            $percent = (@InetGetBytesRead / $size ) * 100
                            ProgressSet($percent)
                        WEnd
                ProgressOff()
        EndIf
    Next
WEnd
Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

The code you posted works great for 4 of the 5 podcasts I am trying to get but last one I am trying to get doesn't use <link> </link>. Looking at the source I can see that the link I want is in this:

<feedburner:origEnclosureLink xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://www.podtrac.com/pts/redirect.mp3/zdpub.vo.llnwd.net/o2/dltv/episode229/dl.tv.229.mp3</feedburner:origEnclosureLink>

I'm pretty sure that all that would need to be changed in the code is this line

$links = StringRegExp($Result, '(?i)(?s)(?:.*?)<link>(.*?)</link>', 1, $nOffset)

but what I was wondering if there is a way to make this more universal. I change the script to use an .ini file for the site, amount of podcasts to get and where to save it. Here is what I did:

Dim $objHTTP
Dim $objReturn
Dim $Result
Dim $packageQueryUrl = IniReadSection ( "PodCenter.ini", "Sites" )
$settings = IniReadSection ( "PodCenter.ini", "Settings" )



For $b = 1 To $packageQueryUrl[0][0] Step 1
    $objHTTP = ObjCreate("Microsoft.XMLHTTP")
    $objHTTP.Open("Get", $packageQueryUrl[$b][1], False)
    $objHTTP.Send
    $Result = $objHTTP.ResponseText
    
    $podCasts = 0
    $nOffset = 0
    
 
    While $podCasts <= $settings[1][1]
        $podCasts = $podCasts + 1
        $links = StringRegExp($Result, '(?i)(?s)(?:.*?)<link>(.*?)</link>', 1, $nOffset)
        If @error = 0 Then
            $nOffset = @extended
        Else
            ExitLoop
        EndIf
        For $i = 0 To UBound($links) - 1
            $out = StringRegExpReplace($links[$i], '\s', '', 1)
            If Not StringInStr($out, ".mp3", 0) Then
            Else
                $get = $links[0]
                $get = StringRegExpReplace($get, '\s', '')
                $name = StringRegExp($get, '(?i)(?s)(?:.*)/(.*?).mp3', 1)
                    If Not FileExists( $settings[2][1] ) Then DirCreate( $settings[2][1] )
                ConsoleWrite("MP3 Link: " & $get & @CRLF & "MP3 Name: " & $name[0] & ".mp3" & @CRLF)
                InetGet($get, $settings[2][1] & $name[0] & ".mp3", 0, 1)
                    ProgressOn("Download Manager", "Downloading: " & $name[0] & ".mp3")
                        $size = InetGetSize($get)
                            While @InetGetActive
                                $percent = (@InetGetBytesRead / $size ) * 100
                                ProgressSet($percent)
                            WEnd
                    ProgressOff()
            EndIf
        Next
    WEnd
    
    
    
Next

This is the .ini I am using:

[Settings]
Podcasts = 3
Location = C:\Documents and Settings\Administrator\My Documents\Downloads\temp\




[Sites]
Site1 = http://www.wfan.com/pages/podcast/801.rss
Site2 = http://rss.cnn.com/services/podcasting/newscast/rss.xml
Site3 = http://sports.espn.go.com/espnradio/podcast/feeds/itunes/podCast?id=2445552
Site4 = http://podcast.msnbc.com/audio/podcast/MSNBC-TDY-PODCAST-MP3.xml
Site5 = http://feeds.ziffdavis.com/ziffdavis/dltvpodcast

Site5 is the one I am having trouble with.

Is it even possible to make the script so I can get the podcast from a bunch of different sites. The only pattern that I can see them all having is that they all end in .mp3. Can you use StringRegExp to search the .xml file until it finds .mp3 then capture backwards to say http:// part?

Thanks again for your help it is very much appreciated.

Link to comment
Share on other sites

The code you posted works great for 4 of the 5 podcasts I am trying to get but last one I am trying to get doesn't use <link> </link>. Looking at the source I can see that the link I want is in this:

<feedburner:origEnclosureLink xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://www.podtrac.com/pts/redirect.mp3/zdpub.vo.llnwd.net/o2/dltv/episode229/dl.tv.229.mp3</feedburner:origEnclosureLink>

I'm pretty sure that all that would need to be changed in the code is this line

$links = StringRegExp($Result, '(?i)(?s)(?:.*?)<link>(.*?)</link>', 1, $nOffset)

but what I was wondering if there is a way to make this more universal. I change the script to use an .ini file for the site, amount of podcasts to get and where to save it. Here is what I did:

Dim $objHTTP
Dim $objReturn
Dim $Result
Dim $packageQueryUrl = IniReadSection ( "PodCenter.ini", "Sites" )
$settings = IniReadSection ( "PodCenter.ini", "Settings" )



For $b = 1 To $packageQueryUrl[0][0] Step 1
    $objHTTP = ObjCreate("Microsoft.XMLHTTP")
    $objHTTP.Open("Get", $packageQueryUrl[$b][1], False)
    $objHTTP.Send
    $Result = $objHTTP.ResponseText
    
    $podCasts = 0
    $nOffset = 0
    
 
    While $podCasts <= $settings[1][1]
        $podCasts = $podCasts + 1
        $links = StringRegExp($Result, '(?i)(?s)(?:.*?)<link>(.*?)</link>', 1, $nOffset)
        If @error = 0 Then
            $nOffset = @extended
        Else
            ExitLoop
        EndIf
        For $i = 0 To UBound($links) - 1
            $out = StringRegExpReplace($links[$i], '\s', '', 1)
            If Not StringInStr($out, ".mp3", 0) Then
            Else
                $get = $links[0]
                $get = StringRegExpReplace($get, '\s', '')
                $name = StringRegExp($get, '(?i)(?s)(?:.*)/(.*?).mp3', 1)
                    If Not FileExists( $settings[2][1] ) Then DirCreate( $settings[2][1] )
                ConsoleWrite("MP3 Link: " & $get & @CRLF & "MP3 Name: " & $name[0] & ".mp3" & @CRLF)
                InetGet($get, $settings[2][1] & $name[0] & ".mp3", 0, 1)
                    ProgressOn("Download Manager", "Downloading: " & $name[0] & ".mp3")
                        $size = InetGetSize($get)
                            While @InetGetActive
                                $percent = (@InetGetBytesRead / $size ) * 100
                                ProgressSet($percent)
                            WEnd
                    ProgressOff()
            EndIf
        Next
    WEnd
    
    
    
Next

This is the .ini I am using:

[Settings]
Podcasts = 3
Location = C:\Documents and Settings\Administrator\My Documents\Downloads\temp\




[Sites]
Site1 = http://www.wfan.com/pages/podcast/801.rss
Site2 = http://rss.cnn.com/services/podcasting/newscast/rss.xml
Site3 = http://sports.espn.go.com/espnradio/podcast/feeds/itunes/podCast?id=2445552
Site4 = http://podcast.msnbc.com/audio/podcast/MSNBC-TDY-PODCAST-MP3.xml
Site5 = http://feeds.ziffdavis.com/ziffdavis/dltvpodcast

Site5 is the one I am having trouble with.

Is it even possible to make the script so I can get the podcast from a bunch of different sites. The only pattern that I can see them all having is that they all end in .mp3. Can you use StringRegExp to search the .xml file until it finds .mp3 then capture backwards to say http:// part?

Thanks again for your help it is very much appreciated.

You don't really have to mess with the line, just put a second check in there with the following regex:

(?i)(?s)(?:feedburner:.*)>(.*?)(?:</feedburner.*?)

So you would have:

$links = StringRegExp($Result, '(?i)(?s)(?:.*?)<link>(.*?)</link>', 1, $nOffset)
BLAH BLAH BLAH
$links = StringregExp($result, '(?i)(?s)(?:feedburner:.*)>(.*?)(?:</feedburner.*?)', 1, $nOffset)

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

You even could Change the Ini

[Settings]
Podcasts = 3
Location = C:\Documents and Settings\Administrator\My Documents\Downloads\temp\




[Sites]
Site1 = http://www.wfan.com/pages/podcast/801.rss
Site2 = http://rss.cnn.com/services/podcasting/newscast/rss.xml
Site3 = http://sports.espn.go.com/espnradio/podcast/feeds/itunes/podCast?id=2445552
Site4 = http://podcast.msnbc.com/audio/podcast/MSNBC-TDY-PODCAST-MP3.xml
Site5 = http://feeds.ziffdavis.com/ziffdavis/dltvpodcast

[OPtREGEXP]
Site3=(?i)(?s)(?:feedburner:.*)>(.*?)(?:</feedburner.*?)

and in AutoIT:

$pattern = IniRead("PodCenter.ini","OPtREGEXP",$packageQueryUrl[$b][0],'(?i)(?s)(?:.*?)<link>(.*?)</link>')
        $links = StringRegExp($Result, $pattern, 1, $nOffset)
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 1 year later...

What a neat script - I love it

It needs a Sleep() value under While statement though. Else it will max the CPU.

Example:

While @InetGetActive

Sleep(250)

$percent = (@InetGetBytesRead / $size ) * 100

ProgressSet($percent)

WEnd

I modified it a bit to do a TrayTip instead of Progress Bar:

Example:

While @InetGetActive
Sleep(250)
TrayTip("Downloading", "File:  " & $name[0] & ".mp3     " & "Bytes = " & @InetGetBytesRead, 10, 0)
WEnd
Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

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