Results 1 to 9 of 9

Thread: [RESOLVED] trying to automate "save target as..."

  1. #1

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    Resolved [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.
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: trying to automate "save target as..."

    But when I use normal download methods in vB6
    what have you tried?

    what do the links to the mp3 look like?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    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.
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  4. #4

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    Re: trying to automate "save target as..."



    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
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  5. #5

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    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.
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [RESOLVED] trying to automate "save target as..."

    also sendkeys does not work in w7, permission denied error
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    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.
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    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.
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width