+ Reply to Thread
Results 1 to 12 of 12

Login and Download CSV File

  1. #1
    Registered User
    Join Date
    10-01-2012
    Location
    Indianapolis, Indiana
    MS-Off Ver
    Excel 2010
    Posts
    51

    Login and Download CSV File

    Hey guys, I know there are other threads on here about this process but I havn't found one with the problem I'm having and I think I know the reason.

    So I have this procedure that logs into a website then travels to another page to download a CSV file..the problem I'm having is with the download section. When I go to download the file, a file IS downloaded but it is the HTML text of the page rather than the CSV file.

    I think it may have to do with how I'm logging in then using a different methods to download the file..any help would be greatly appreciated.

    Please Login or Register  to view this content.
    Thanks!

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Login and Download CSV File

    Try using:
    Please Login or Register  to view this content.
    Instead of
    Please Login or Register  to view this content.
    Not sure if it will work since I can't log into the site, but worth a punt

  3. #3
    Registered User
    Join Date
    10-01-2012
    Location
    Indianapolis, Indiana
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: Login and Download CSV File

    Thanks for the try Kyle, but no luck. the downloaded file still only contained the html output. i think it has something to do with the logging in process and for somereason its not holding the session to the download section. but tbh I have no idea at this point.

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Login and Download CSV File

    Yeah, that's why it doesn't work. Your second request isn't passing the cookie from the first.

    Give this a whirl, no idea if it will work and I've written it on my mac and don't have Excel so I might have mistyped something

    Please Login or Register  to view this content.

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Login and Download CSV File

    The theory is that since we're using the same object to both log in and request the file, the cookie should be passed along.

    I'm not 100% whether this will log you in since they have used something to prevent hacking, and posting to a web server like this is a bit of trial and error anyway

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Login and Download CSV File

    P.S if you're interested in how I got the parameters to pass and to help with a bit of trouble shooting, have a look here http://www.mrexcel.com/forum/general...uestion-2.html Where I wrote a post about how to send stuff to a webserver without internet explorer

  7. #7
    Registered User
    Join Date
    10-01-2012
    Location
    Indianapolis, Indiana
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: Login and Download CSV File

    Great, thanks Kyle. Im working on an ActiveX error now. Says: "ActiveX component can't create object." I believe that's just a problem on my end with just registering the Activex DLL and OCX's

    Gona start working on that problem then I can dive into the code and see if any more pop-up. thanks again!

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Login and Download CSV File

    haha nope, my error, missed out WinHttp.WinHttpRequest.5.1 from the CreateObject("")

  9. #9
    Registered User
    Join Date
    10-01-2012
    Location
    Indianapolis, Indiana
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: Login and Download CSV File

    Ahh gotcha, yup that fixed it. I think its getting whiddled(sp?) down..there was an error about: "This method can't be called until the Send method has been called". It referenced the line
    Please Login or Register  to view this content.
    as the problem. I'm assuming just do an if statement but i tried to throw that in, but it wasn't loving how I tried to do it.

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Login and Download CSV File

    Try this:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    10-01-2012
    Location
    Indianapolis, Indiana
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: Login and Download CSV File

    Well figured it out, was just simply sending another .Open statement to the logout file. Thanks again Kyle, you really helped me out here.

    Here is the end result of the work. It will log into a website, download a CSV file, delete the old file of the same name and save the new CSV file in place of the old one. If anyone else needs the code, I have posted it below.

    Please Login or Register  to view this content.
    Last edited by NeoFlex; 10-05-2012 at 10:59 AM.

  12. #12
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Login and Download CSV File

    Great stuff

    I didn't actually know the answer to that one but I suspected it wouldn't like you logging in as the same user twice. It uses a nifty method of stopping cross site scripting which means there's a unique key linked to you as a user. I guess that needed clearing (which logging out would do) before trying to log in again

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1