Jump to content

How to code it using AutoIT?


Recommended Posts

Referring to following coding and image, I would like to know on how to locate the link and click it for downloading file using AutoIT.

Does anyone have any suggestions?
Thanks in advance for any suggestions

 

#include <IE.au3>
While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
WEnd
Global $sHTMLSavePath = "D:\Download"  ;~ Folder Path to Save Excel Documents
Global $oIE = _IECreate("https://www.hkex.com.hk/Market-Data/Futures-and-Options-Prices/Equity-Index/Hang-Seng-Index-Futures-and-Options?sc_lang=en#&product=HSI")
Sleep(5000)     ;~ Wait while page loads

Func _GetSiteData($p_oIEObject, $p_sLinkText)
    Local $oAnchors, $sLinkText, $hFileOpen, $bLinkText = False
    Local $oTableCells = _IETagNameGetCollection($oIE, "options")
    For $oTableCell In $oTableCells
        If $oTableCell.className = "ete title_right" Then
        How to click Export to Excel and download file into D:\Download folder and name it "Temp.xlsx"
        EndIf
    Next
EndFunc

 

 

Option.png

Edited by oemript
Link to comment
Share on other sites

Referring to following coding, Message Step 2 is shown, but there is nothing show up for saving files.

Do you have any suggestions on what wrong it is?
Thank you very much for any suggestions (^v^)

 

#include <IE.au3>
While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
WEnd
Global $sFileSavePath = "D:\Download"  ;~ Folder Path to Save Excel Documents
Global $oIE = _IECreate("https://www.hkex.com.hk/Market-Data/Futures-and-Options-Prices/Equity-Index/Hang-Seng-Index-Futures-and-Options?sc_lang=en#&product=HSI")
WinSetState(_IEPropertyGet($oIE, "title"), "", @SW_MAXIMIZE)
Sleep(5000)     ;~ Wait while page loads
MsgBox(0, "Start", "Start")
Local $oTableCells = _IETagNameGetCollection($oIE, "options")
For $oTableCell In $oTableCells
   If $oTableCell.className = "ete title_right" Then
      MsgBox(0, "Step 2", "Step 2")
     $oExcelExport = _IEGetObjById("ete")
      _IEAction($oExcelExport, "click")
      ; It should pop up a window to save file as "HSI_Options.xlsx"
      ; I would like to save under D:\Download Folder"
   EndIf
Next
MsgBox(0, "End", "End")

 

Option.png

Edited by oemript
Link to comment
Share on other sites

Sorry forgot the object, you only need:

#include <IE.au3>
While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
WEnd
Global $sFileSavePath = "D:\Download"  ;~ Folder Path to Save Excel Documents
Global $oIE = _IECreate("https://www.hkex.com.hk/Market-Data/Futures-and-Options-Prices/Equity-Index/Hang-Seng-Index-Futures-and-Options?sc_lang=en#&product=HSI")
Sleep(25000)     ;~ Wait while page loads
WinSetState(_IEPropertyGet($oIE, "title"), "", @SW_MAXIMIZE)
$oExcelExport = _IEGetObjById($oIE, "ete")
_IEAction($oExcelExport, "click")

 

Link to comment
Share on other sites

I try to look for any related Excel saving file reference, but following command seems not able to save.

#include <IE.au3>
While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
WEnd
Global $sFileSavePath = "D:\Download"  ;~ Folder Path to Save Excel Documents
Global $oIE = _IECreate("https://www.hkex.com.hk/Market-Data/Futures-and-Options-Prices/Equity-Index/Hang-Seng-Index-Futures-and-Options?sc_lang=en#&product=HSI")
WinSetState(_IEPropertyGet($oIE, "title"), "", @SW_MAXIMIZE)
Sleep(25000)     ;~ Wait while page loads
$oExcelExport = _IEGetObjById($oIE, "ete")
_IEAction($oExcelExport, "click")
_Excel_BookSaveAs($oExcelExport, $sFileSavePath, $xlsx, True)

Do you have any suggestions on what wrong is "_Excel_BookSaveAs" command to save file "HSI_Options.xlsx" under D:\Download\?
Thank you very much for any suggestions (^v^)

 

Edited by oemript
Link to comment
Share on other sites

Am i missing something ? i dont see the ID of the object to be "ete". So it  could be identified by either the class or the inner text.

@Edit after opening the site i saw it - the ID is ETE so , easy thing.

@oemript

The easy and dirty thing is to set IE to download all attachments to D:\Download\  without prompting :) The other option is to use controlclick or WinHttp.au3 by @trancexx.

Edited by Juvigy
FOund it.
Link to comment
Share on other sites

@Juvigy is correct I was looking at the top Future "Export to Excel" link rather than the Options "Export to Excel" link, the latter would require classname, like so, not pretty but don't have time to look into alternatives.

#include <IE.au3>
While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
WEnd
Global $sFileSavePath = "D:\Download"  ;~ Folder Path to Save Excel Documents
Global $oIE = _IECreate("https://www.hkex.com.hk/Market-Data/Futures-and-Options-Prices/Equity-Index/Hang-Seng-Index-Futures-and-Options?sc_lang=en#&product=HSI")
Sleep(10000)     ;~ Wait while page loads
Local $sPageTitle = _IEPropertyGet($oIE, "title")
WinSetState($sPageTitle, "", @SW_MAXIMIZE)
$oDivs = _IETagNameGetCollection($oIE, "div")
For $oDiv In $oDivs
    If $oDiv.className = "options" Then
        $oExcelOption = $oDiv.lastElementChild
        _IEAction($oExcelOption, "click")
        ExitLoop
    EndIf
Next
$oLinks = _IELinkGetCollection($oIE)
$oLink = $oLinks($oLinks.length - 1)
_IEAction($oLink, "Focus")
Sleep(3000)
ControlSend($sPageTitle, "", "DirectUIHWND1", "{TAB 2}{ENTER}")

 

Link to comment
Share on other sites

1) Instead of using ControlSend, would it be possible to save (overwrite) into specific folder? such as D:\Download directory.

2) For controlSend, would it be possible to select SaveAs instead of Save? and select D:\Download directory and save with overwrite any existing filename.  I cannot find any related materials to select Save As under this situation.

ControlSend($sPageTitle, "", "DirectUIHWND1", "{TAB 2}{ENTER}")

3) or other alternative, if there is a fixed URL, it can be downloaded through powershell.  Under this situation, would it be possible to determine any fixed path? which seems that is generated by java and I cannot find any fixed path within my knowledge.

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

1 hour ago, Subz said:

@Juvigy

#include <IE.au3>
While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
WEnd
Global $sFileSavePath = "D:\Download"  ;~ Folder Path to Save Excel Documents
Global $oIE = _IECreate("https://www.hkex.com.hk/Market-Data/Futures-and-Options-Prices/Equity-Index/Hang-Seng-Index-Futures-and-Options?sc_lang=en#&product=HSI")
Sleep(10000)     ;~ Wait while page loads
Local $sPageTitle = _IEPropertyGet($oIE, "title")
WinSetState($sPageTitle, "", @SW_MAXIMIZE)
$oDivs = _IETagNameGetCollection($oIE, "div")
For $oDiv In $oDivs
    If $oDiv.className = "options" Then
        $oExcelOption = $oDiv.lastElementChild
        _IEAction($oExcelOption, "click")
        ExitLoop
    EndIf
Next
$oLinks = _IELinkGetCollection($oIE)
$oLink = $oLinks($oLinks.length - 1)
_IEAction($oLink, "Focus")
Sleep(3000)
ControlSend($sPageTitle, "", "DirectUIHWND1", "{TAB 2}{ENTER}")

 

 

Edited by oemript
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...