Jump to content

Help with clicking on link in webpage


Recommended Posts

I am trying to navigate to http://sports.espn.go.com/espnradio/podcas...hive?id=2445552 and click on the top download link ( there are a few links on page named download I just want the top one).

You forgot to say what you've done so far. Do you have the page opened with _IECreate()? Have you tried to any of the _IE* functions to get the link?

:)

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

Sorry I was gona post the stuff I tried but I thought it would be such a simple thing I decided not to.

Tried this

#include <IE.au3>
$oIE =_IECreate ("http://sports.espn.go.com/espnradio/podcast/archive?id=2445552")
_IEImgClick ($oIE, "Download", "alt")

This opens IE but doesn't open the download window

Tried using IE-Builder when I viewed the image info from the webpage I saw this

Img SRC: http://assets.espn.go.com/i/espnradio/podc...on_download.gif

alt Text: Download

so I tried using

#include <IE.au3>
$oIE =_IECreate ("http://sports.espn.go.com/espnradio/podcast/archive?id=2445552")
_IEImgClick ($oIE, "http://assets.espn.go.com/i/espnradio/podcast/images/button_download.gif")

Both of them give me a warning at the top of IE so I had to click on the bar and select download but I think that it is downloading the .gif not trying to download the mp3 file that I want.

I was looking at the help file and saw _IELinkClickByIndex but got lost trying to use that.

My over all goal was to make an autoit script that could download afew different podcast that I define in an .ini file but seeing how I am getting stuck on just clicking on a link on a webpage I'm not sure anymore :)

Link to comment
Share on other sites

You could do something like this:

#include <IE.au3>
$oIE =_IECreate ("http://sports.espn.go.com/espnradio/podcast/archive?id=2445552")
$oLinks = _IELinkGetCollection($oIE)

For $oLink In $oLinks
    If StringInStr($oLink.href, ".mp3") Then
        ConsoleWrite($oLink.href & @LF)
        _IENavigate($oIE, $oLink.href)
        ExitLoop
    EndIf
Next

But if it's just that one exact file you want, you could just use a static link instead, which in this case is:

http://podloc.andohs.net/dloadTrack.mp3?pr...tofmm080403.mp3

But if you take a closer look at the link, you don't need the http://podloc.andohs.net/dloadTrack.mp3?prm=1641x part of it(which would probably be faster to access initially):

http://query-origin.andohs.net/8000A6/cont...tofmm080403.mp3

Link to comment
Share on other sites

Will http://query-origin.andohs.net/8000A6/cont...tofmm080403.mp3 always give me the newest podcast. I thought if I tried to get link straight to file that I would always get the same show. The code you posted works great .... will that always grab the newest show?

Thanks for your help with this.

Just to make sure I made myself clear I want to always grab the newest show.

Link to comment
Share on other sites

Both of them give me a warning at the top of IE so I had to click on the bar and select download but I think that it is downloading the .gif not trying to download the mp3 file that I want.

The messages written to the console try to be very helpful. Please look at tehm carefully and post them when you are asking for 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

Link to comment
Share on other sites

When I run

#include <IE.au3>
$oIE =_IECreate ("http://sports.espn.go.com/espnradio/podcast/archive?id=2445552")
$oLinks = _IELinkGetCollection($oIE)

For $oLink In $oLinks
    If StringInStr($oLink.href, ".mp3") Then
        ConsoleWrite($oLink.href & @LF)
        _IENavigate($oIE, $oLink.href)
        ExitLoop
    EndIf
Next

I get this >"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\Administrator\My Documents\Autoit Scripts\Podcast\test.au3" in the console not sure what that means but script seems to do what I want it to do. I just need to figure out how to automate the clicking on Save button on IE download window.

Now that the first site seems to be working I tried to change code a little bit to this

#include <IE.au3>
Global $wSite1 = "http://sports.espn.go.com/espnradio/podcast/archive?id=2445552"
Global $wSite2 = "http://www.wfan.com/pages/119297.php"
$oIE =_IECreate ($wSite1)
$oLinks = _IELinkGetCollection($oIE)

For $oLink In $oLinks
    If StringInStr($oLink.href, ".mp3") Then
        ConsoleWrite($oLink.href & @LF)
        _IENavigate($oIE, $oLink.href)
        ExitLoop
    EndIf
Next

As you can see all I did was take the sites and put them in a variable .. my thought is that I would define all the sites at the top and just keep adding that FOR loop for each site. I tested this code and seems to work fine but when I changed

$oIE =_IECreate ($wSite1) to $oIE =_IECreate ($wSite2) I don't get the download window. The page loads then IE flashes like its going to another page or clicked on link and I see green progress bar at bottom of IE start to go up slowly but never gets to 100%. So I thought maybe I screwed something up with what I added so I just put http://www.wfan.com/pages/119297.php in the first script and that does the same thing .... doesn't give me the download window.

FreeFry I am not sure if you intended that first script to work with different sites or not. Would it even be possible to make something that works with all sites or will I have to adjust the for loop in the script for each site.

Thanks again for your help it is very much appreciated.

Link to comment
Share on other sites

Now that the first site seems to be working I tried to change code a little bit to this

#include <IE.au3>
Global $wSite1 = "http://sports.espn.go.com/espnradio/podcast/archive?id=2445552"
Global $wSite2 = "http://www.wfan.com/pages/119297.php"
$oIE =_IECreate ($wSite1)
$oLinks = _IELinkGetCollection($oIE)

For $oLink In $oLinks
    If StringInStr($oLink.href, ".mp3") Then
        ConsoleWrite($oLink.href & @LF)
        _IENavigate($oIE, $oLink.href)
        ExitLoop
    EndIf
Next

As you can see all I did was take the sites and put them in a variable .. my thought is that I would define all the sites at the top and just keep adding that FOR loop for each site. I tested this code and seems to work fine but when I changed

$oIE =_IECreate ($wSite1) to $oIE =_IECreate ($wSite2) I don't get the download window. The page loads then IE flashes like its going to another page or clicked on link and I see green progress bar at bottom of IE start to go up slowly but never gets to 100%.

You'll have to look if the links are "ok", check in Scite what the ConsoleWrite is outputting..

So I thought maybe I screwed something up with what I added so I just put http://www.wfan.com/pages/119297.php in the first script and that does the same thing .... doesn't give me the download window.

The second site does not have direct links to the mp3s like the first site has, on the second site the links go to a php script that pulls out the links for you(this one for example: http://www.wfan.com/episode_download.php?c...tentId=1754229).

You'll have to modify the StringInStr to look for "contentType=36" instead of ".mp3", and perhaps it will work. :)

FreeFry I am not sure if you intended that first script to work with different sites or not. Would it even be possible to make something that works with all sites or will I have to adjust the for loop in the script for each site.

It should work for any site that has direct links to the mp3s, but not on sites like the second one, as in that case, you'll have to modify the loop.
Link to comment
Share on other sites

Thanks FreeFry for your help again. I tried what you mentioned by having the code search for "contentType=36" but http://www.wfan.com/pages/119297.php doesn't seem work by just getting the link to the podcast and having IE browse to that link. I think the link needs to be clicked to work so I tried changing

_IENavigate($oIE, $oLink.href)
to
_IEAction($oLink, "Click")

this seems to click on the link because I see a new IE window open but after about 15-20 seconds the new IE window disappears.

Sorry for all the questions .... seems like I can't get very far with this script without having to come back here and ask for more help.

Link to comment
Share on other sites

SUCCESS !!!!

Got http://www.wfan.com/pages/119297.php to work by using this

$hwnd = _IEPropertyGet($oIE, "hwnd")
       _IEAction ($oLink, "focus")
        ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")

Now to work on adding maybe .ini file to list the sites and get the script to work the download window.

Thanks again for the help

Link to comment
Share on other sites

I got this script working pretty good using this

#include <IE.au3>
$var =  IniReadSection( "test.ini", "sites" )
$var2 = IniReadSection( "test.ini", "linkref" )
$a = 1
    For $i = 1 To $var[0][0]
        $wSite = $var[$i][1]
        ConsoleWrite ( $wSite )
        $oIE =_IECreate ($wSite)
        $oLinks = _IELinkGetCollection($oIE)
        $linkref = $var2[$a][1]
            For $oLink In $oLinks
                If StringInStr($oLink.href, $linkref) Then
                    ConsoleWrite($oLink.href & @LF)
                    $hwnd = _IEPropertyGet($oIE, "hwnd")
                    _IEAction ($oLink, "focus")
                    ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
                    ExitLoop
                EndIf
            Next
            
            $a = $a + 1
            sleep ( 1000 )
            WinWait( "File Download - Security Warning")
            sleep ( 2000 )
            ControlClick( "File Download - Security Warning", "", 4427 )
            WinWait( "Save As")
            sleep( 2000 )
            Send( "{Enter}" ) 
    Next

This reads from an .ini file and gets the site and what word to use when picking out the link to download. This seems to work ok but there are few things I didn't like about it. So I tried subscribing to the RSS feeds on the sites and when I did this I noticed that all the files were direct links to .mp3s instead of some of the sites using a script to get the link to the mp3. I also noticed that the links were much faster to return with the download window. The link for WFAN site takes like 30 seconds to bring up download window.

The problem I am having now is that it if I use the link from the RSS feed the script doesn't get passed $oIE =_IECreate ($wSite) ( I think this is because the script thinks IE is still loading) I changed $oIE =_IECreate ($wSite) to $oIE =_IECreate ($wSite, 0, 1, 0) and adding a sleep( 5000 ) in there to get the script passed that but I then get this error:

http://www.wfan.com/pages/podcast/801.rssC:\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

I tried using the example script in the help file for _IELinkGetCollection and changing the site to http://www.wfan.com/pages/podcast/801.rss in it but I get the same error. Here is the example code with just the site changed that I used.

; *******************************************************
; 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

Is there anyway to get around this error ... not really sure what that error means.

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