Jump to content
Redd500

Need to save file without direct access to actual file or GUI

Recommended Posts

Redd500

So I'm currently writing a script to navigate a bunch of webpages to login and download a couple .zip files. It needs to run in Windows Task Scheduler while I am not logged in, so I don't have access to GUI stuff. It runs perfectly fine until it actually has to download the files, because the links you click to download the files aren't the actual files and instead generate or fetch the files from a separate server and download them as the browser would normally.

Trying InetGet() hasn't worked because I'm assuming it needs direct access to the file from the URL provided, which I don't have.

And simply automating a click like with _IEAction() won't work because that would just pull up the IE Download window which I can't access due to no GUI.

I'm also assuming I don't have access to the server where the files are because these files are coming from IBM so they are probably securing it.

The href is just a bunch of properties passed to the site to know what file is needed.

I am at a loss and need some help.

Share this post


Link to post
Share on other sites
Danp2

Unfortunately, there isn't enough information provided to know how to help. Can you tell us more about the website(s) involved? Are they public facing? Can you show us what the link URL looks like? How do they differ from the actual download link (press Ctrl+J to bring up the download window)?

Can you show us the HTML from one of the site's pages, including any Javascript?

Share this post


Link to post
Share on other sites
Redd500
1 hour ago, Danp2 said:

Unfortunately, there isn't enough information provided to know how to help. Can you tell us more about the website(s) involved? Are they public facing? Can you show us what the link URL looks like? How do they differ from the actual download link (press Ctrl+J to bring up the download window)?

Can you show us the HTML from one of the site's pages, including any Javascript?

Sure. The website is definitely not public facing, as the link to get there involves www-01.ibm.com followed by specific paths to get to what I need, and then I have to navigate to the login page and login with our company information to actually get to the download links needed. The link href is something like DownloadCSV.do?regionCode=XXX&fileCntryName=XXX etc. with a bunch of other properties included. The actual download link follows a format of "CountryMonthDayYear.zip". I don't know if I'm allowed to include the HTML unfortunately, but I can post how I find the link and click it:

Local $tags = _IETagNameGetCollection($oIE, "tr")

;search for the download link and click it and wait.
For $tag in $tags
    $textValue = $tag.innerHTML
    If StringInStr($textValue, "Software - United States") > 0 Then
        Local $link = _IETagNameGetCollection($tag, "a", 0)
        _IEAction($link, "click")
        _IELoadWait($oIE)
        If @error = 0 Then
            ExitLoop
        EndIf
   EndIf
Next

The actual link doesn't have an id, name, or unique text I can use so instead I have to look through elements for specific text and then click the link within that element.

Share this post


Link to post
Share on other sites
jdelaney

Using AutoIT at IBM?  That's not on their approved list! (kidding)

I suggest my signature when people do loops to find IE elements.  It allows you to do complex searches, and contains all the loops wiithin it, so you only need a single call for each situation.

Yours (guessing) would be like '//tr//*[contains(.,"Software - United States")]//a'

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Juvigy

IE also has developer tools. I would say that there is a java function attached to the onclick of the download element. You can call it directly and modify it a bit to save the file without asking for save path. Can you post the download button html code?

Share this post


Link to post
Share on other sites
Redd500

Right now I have access to Chrome, as I only use IE on the remote server we're using for this script. But I did find what I think is the HTML code.

<tr>
  <!-- country -->
    <td style="padding-top: 13px">
        Software - United States
        
    </td>
    
  <!-- pricing -->
    <td class="ibm-ind-link">
        <p><a class="ibm-download-link"  href="DownloadCSV.do?*LOTS OF VARIOUS PROPERTIES GO HERE*">SRP/SVP</a></p>
        
    </td>
    
  <!-- date -->
    <td style="padding-top: 13px">
        <p>17 Apr 2018</p>

    </td>
    
  <!-- approximate size -->
    <td style="padding-top: 13px">
        <p>943.64 kb (.zip file) </p>

    </td>
</tr>

I also got some stuff from the Event Listeners for the link.

image.png.96e453d1c080751ba2f2ba5abaa0ee39.png

Share this post


Link to post
Share on other sites
Danp2
4 hours ago, Juvigy said:

IE also has developer tools.

Yes, I know. However, I avoid them because they don't work as well IMO and I find it easier to view the events in FF. :)

Edit: Here's an example --

image.png.95d557859fd10226203fc1d29176526a.png

Edited by Danp2
add image

Share this post


Link to post
Share on other sites
Redd500

Yep I found the click event and can copy and paste it, and it's all minimized onto one line that stretches across several pages if I were to paste it here. It also has this attached:

// Licensed Materials - Property of IBM, eluminate.js (US Build # 4.21.99 Date/Time: 20180321-14:32), (C) Copyright IBM Corporation 2018. U.S. Government Users Restricted Rights:  Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

 

Share this post


Link to post
Share on other sites
Redd500

Alright, just wanted to make sure lol. Don't want to share stuff I'm not allowed to share, and I don't know where that line is so I tend to err on the side of caution.

But yeah that's what the onclick event is for the link.

Share this post


Link to post
Share on other sites
Danp2

Can you show us the actual onClick code (not the eluminate.js library)? I'm trying to see if it's where we need to focus or if we need more details on the DownloadCSV.do href.

Share this post


Link to post
Share on other sites
Redd500
function cW(b, a) {
    CI();
    var b = CG(b);
    if (b) {
        C9(b, a)
    }
    CJ(1);
    CE();
    if (a) {
        setTimeout(a, cm_LinkClickDelayInterval)
    } else {
        if (cm_LinkClickDelay) {
            if (b) {
                setTimeout('document.location = "' + b.href + '"', cm_LinkClickDelayInterval);
                return false
            } else {
                return true
            }
        }
    }
}

I got this by pretty-printing the file and looking back at the event for the link.

Share this post


Link to post
Share on other sites
Danp2

Since we don't have access to the site, you'll need to do some debugging on your end to follow the code and figure out what values are being passed to the cW function and if calling it directly works to download the file. If not, then you probably need to investigate DownloadCSV.do as mentioned above.

Share this post


Link to post
Share on other sites
Redd500

What's being passed to the cW function is the MouseEvent for the <a> element I clicked on and undefined. I don't think I can replicate that by calling it directly unfortunately.

Share this post


Link to post
Share on other sites
Redd500

I guess with Jquery I can just use the href and then catch the file myself? Then I can actually use InetGet()?

Share this post


Link to post
Share on other sites
Dent

Did it work? I'm having this exact same issue

Share this post


Link to post
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

×