[RESOLVED] trying to automate "save target as..."
Hey all.
I'm a member on a website and I have access to a large archive of files.
The files are MP3.
I can go straight to the site and download them.
I usually use "Save Target As.." becuase if I click right on them, they open in Media Player.
I've been trying to automate the process so they download without me going to the site.
But when I use normal download methods in vB6, the file content is HTML that is basically a login page. I've tried it when I'm logged in to the website and even make sure by downloading a file beforehand. But when I run the app, It gives me HTML again.
I need a way to automate the "Save Target As.." function.
Now I'm thinking of switching to a web browser control, but I don't know what I can do with that after navigating to the correct page.
Something about innerHTML maybe, parse the text, then .... I don't know how to save target as, rather than use the download link in the html.
Does anybody else know this?
I'd appreciate the help. I spend a couple hours a week doing this manually.
Thanks.
Re: trying to automate "save target as..."
Quote:
But when I use normal download methods in vB6
what have you tried?
what do the links to the mp3 look like?
Re: trying to automate "save target as..."
same old function I've been using for years with VB6
Public Function DownloadFile(URL, LocalFilename) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
This works with the usual types of files, but for the MP3 it isn't working.
The link to the file doesn't say MP3 in it. It's like:
[site]/cgi-bin/members.cgi?stream=[various parameters]
I've been trying this on a webbrowser for a little while now, and it works like regular IE.
I can click on the link and WMP pops up and starts playing the MP3, or I can right click save as and save the MP3 to my hard drive and play it.
I haven't tried anything further with WB because I haven't used one in years, don't know where to start
what I really want to do is automate the daily opening of the page and saving the files without going to the site daily. I'm a paying member of the site and I'm logged in both in IE and the WB.
Re: trying to automate "save target as..."
:check:
OK. I got it.
For anybody else trying to automate file downloads (esp. MP3) from a website:
I used the webbrowser to navigate to the page, then I loop through the links on the page and if the href text has what I'm looking for, I programatically click the link.
Then I start a timer delay and sendkeys S for save (open/save/cancel).
THen I have a second timer delay and another sendkeys {Enter} for save (for the save as... dialog box).
Then I put on a three minute timer delay and sendkeys {Enter} again for the Download Compete dialog box.
Then WB navigates to the next page if necessary.
The really tricky part of this (and maybe somebody else can explain it) is that the sendkeys command had to be in the timer's event. When I tried it outside the event, such as :
Link.click
Timer1.enabled = true
Do until Timer1.enabled = false
DoEvents
Loop
Sendkeys "S"
It doesn't work, no matter what order you do the above, the Sendkeys doesn't wait. I know Sendkeys has a Wait boolean, but I don't know how it is used. I think I tried it and got the same result.
Anyway, all's well that ends well.
The only issue is the program is functioning blind this way, so two ways it will crash are:
1. if the file doesn't download within 3 minutes (which it should ordinarily)
or
2. if some other program pops up a window while this is running.
Also, in order to make this work, I had to unassociate MP3 from Windows Media Player to stop WMP opening when the link is clicked.
Hope it helps somebody else
Re: trying to automate "save target as..."
Hmm.
Thinking now maybe if I'd taken DoEvents out of the loop it would've forced Sendkeys to wait in above code. Not sure.
Re: [RESOLVED] trying to automate "save target as..."
also sendkeys does not work in w7, permission denied error
Re: [RESOLVED] trying to automate "save target as..."
no it will.
I'm using windows 7.
What you have to do is turn UAC down to the lowest setting "never notify".
I guess if you're going to use the sendkeys app regularly you have to take the risk into account.
Re: [RESOLVED] trying to automate "save target as..."
ok if you are the only one who is going to use the program, no good if distributing
Re: [RESOLVED] trying to automate "save target as..."
right.
in this case,it was just an app to automate something I was doing manually every day.
It's so customized, there would be no demand for distribution.