Jump to content
oemript

How to capture text using AutoIT?

Recommended Posts

Referring to following link, I would like to know on whether it is possible to capture text into text / csv file as shown below

https://www.hkab.org.hk/DisplayInterestSettlementRatesAction.do?lang=en

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

 

Rate.png

Share this post


Link to post
Share on other sites

IEGetTagCollection  is not available on version v3.3.14.3 SciTE

Do you have any suggestions on which version should be tried?
Thank you very much for any suggestions (^v^)

 

Tag.png

Share this post


Link to post
Share on other sites

Referring to following coding, I would like to know on how to locate text and display on message box using IETagNameGetCollection.

Does anyone have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

#include <IE.au3>
#include <MsgBoxConstants.au3>
While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
WEnd
Global $oIE = _IECreate("https://www.hkab.org.hk/DisplayInterestSettlementRatesAction.do?lang=en")
Sleep(5000)     ;~ Wait while page loads
Local $oInputs = _IETagNameGetCollection($oIE, "input")
Local $sTxt = ""
For $oInput In $oInputs
    $sTxt &= $oInput.type & @CRLF
Next
MsgBox($MB_SYSTEMMODAL, "Form Input Type", "Form: " & $oInput.form.name & @CRLF & @CRLF & "         Types :" & @CRLF & $sTxt)

Share this post


Link to post
Share on other sites

Use the browser's built-in Developer Tools to examine the website. This is an essential skill if you want to automate websites. By examining this site, you would learn --

  • The website uses frames
  • The data you see is held inside a table

So, you first need to use switch to the correct frame using _IEFrameGetCollection. Then you should be able to access the table's data using _IETableGetCollection / _IETableWriteToArray.

Share this post


Link to post
Share on other sites
Posted (edited)

Referring to following image, I would like to know on how to access 6 months and 2.04536 by _IETagNameGetCollection, on the other words, what Name should be used for matching in order to retrieve required texts.

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

 

 

 

 

6m.png

Edited by oemript

Share this post


Link to post
Share on other sites

Try this :

#include <Constants.au3>
#include <IE.au3>
#include <Array.au3>

Opt ("MustDeclareVars", 1)

Local $oIE = _IECreate("https://www.hkab.org.hk/DisplayInterestSettlementRatesAction.do?lang=en")
If Not IsObj ($oIE) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error creating IE object")
Local $oFrame = _IEFrameGetObjByName ($oIE,"out")
If Not IsObj ($oFrame) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error searching for frame")
Local $oTDs = _IETagNameGetCollection ($oFrame, "td")
If Not IsObj ($oTDs) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error gathering tag collection")
Local $sValue
For $oTD in $oTDs
  $sValue = _IEPropertyGet ($oTD, "innertext")
  If @error or $sValue = "" Then ContinueLoop
  If $sValue = "6 Months" Then
    $sValue = $oTD.nextElementSibling.innerText
    ExitLoop
  Endif
Next

MsgBox ($MB_SYSTEMMODAL,"",Number($sValue))
_IEQuit ($oIE)

 

Share this post


Link to post
Share on other sites

Referring to following coding and image, if oFrame is not available,  I would like to know on what to look for based on following image.

Do you have any suggestions?

Thank you very much for any suggestions (^v^)

 

#include <Constants.au3>
#include <IE.au3>
#include <Array.au3>

Opt ("MustDeclareVars", 1)

Local $oIE = _IECreate("https://www.cmegroup.com/trading/interest-rates/countdown-to-fomc.html")
If Not IsObj ($oIE) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error creating IE object")
Local $oFrame = _IEFrameGetObjByName ($oIE,"out")
If Not IsObj ($oFrame) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error searching for frame")
Local $oTDs = _IETagNameGetCollection ($oFrame, "td")
If Not IsObj ($oTDs) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error gathering tag collection")
Local $sValue
For $oTD in $oTDs
  $sValue = _IEPropertyGet ($oTD, "innertext")
  If @error or $sValue = "" Then ContinueLoop
  If $sValue = "200-225" Then
    $sValue = $oTD.nextElementSibling.innerText  ;which return 0.0%
    $sValue = $oTD.nextElementSibling.innerText  ;which return 2.0%
    $sValue = $oTD.nextElementSibling.innerText  ;which return 3.9%
    ExitLoop
  Endif
Next

MsgBox ($MB_SYSTEMMODAL,"",Number($sValue))
_IEQuit ($oIE)

 

fomc.png

Share this post


Link to post
Share on other sites

This is the definition for the frame you referenced in the image --

<iframe src="https://cmegroup-tools.quikstrike.net/User/QuikStrikeTools.aspx?viewitemid=IntegratedFedWatchTool" style="width: 100%; height: 885px; overflow: hidden; border: 0px none;" scrolling="no" id="cmeIframe-yoymbhus" class="cmeIframe" frameborder="0"></iframe>

It doesn't have a given name, so using _IEFrameGetObjByName is not an option. But you still need to get a reference to the frame object in order to access it contents. You can use _IEFrameGetCollection with an index value (I believe 0 will work in this case ) or you could use _IEGetObjById,

Share this post


Link to post
Share on other sites

@Danp2 Id is always changing.  And for some reason _IEFrameGetCollection doesn't work for that site. Only way I was able to access it is by using this code :

#include <IE.au3>

Opt ("MustDeclareVars", 1)

Local $oIE = _IECreate("https://www.cmegroup.com/trading/interest-rates/countdown-to-fomc.html")
If Not IsObj ($oIE) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error creating IE object")

Local $oFrames = _IEFrameGetCollection ($oIE)
ConsoleWrite ("Number of frames : " & $oFrames.length & @CRLF)
For $oFrame in $oFrames
  ConsoleWrite (ObjName ($oFrame) & @CRLF) ; it doesn't write anything
Next

Local $oDivs = _IETagNameGetCollection ($oIE, "div")
Local $oObject
For $oDiv in $oDivs
  if $oDiv.className = " cmeIframeContainer" then
    ConsoleWrite ($oDiv.className & @CRLF)
    $oObject = $oDiv.firstElementChild
    ExitLoop
  EndIf
Next

MsgBox ($MB_SYSTEMMODAL,"",ObjName($oObject) & "/" & $oObject.id)

But then the frame object seems empty, no tagcollection is working, empty...

Share this post


Link to post
Share on other sites

@Nine I believe the issue is related to browser restrictions limiting access to cross-domain elements. I was actually able to make it work by navigating to the domain that contains the desired data --

#include <IE.au3>
#include <array.au3>

$oIE = _IECreate("https://www.cmegroup.com/trading/interest-rates/countdown-to-fomc.html")
_IENavigate($oIE, "https://cmegroup-tools.quikstrike.net/User/QuikStrikeView.aspx?viewitemid=IntegratedFedWatchTool")

$oTable = _IETableGetCollection($oIE, 4)
$aData = _IETableWriteToArray($oTable)
_ArrayDisplay($aData)

 

Share this post


Link to post
Share on other sites
Posted (edited)
On 4/21/2019 at 12:39 AM, Danp2 said:

@Nine I believe the issue is related to browser restrictions limiting access to cross-domain elements. I was actually able to make it work by navigating to the domain that contains the desired data --

#include <IE.au3>
#include <array.au3>

$oIE = _IECreate("https://www.cmegroup.com/trading/interest-rates/countdown-to-fomc.html")
_IENavigate($oIE, "https://cmegroup-tools.quikstrike.net/User/QuikStrikeView.aspx?viewitemid=IntegratedFedWatchTool")

$oTable = _IETableGetCollection($oIE, 4)
$aData = _IETableWriteToArray($oTable)
_ArrayDisplay($aData)

Referring to following image, I would like to know on how to click specific tabs in order to retrieve data for different months.

FOMC2.png

javascript:__doPostBack('ctl00$MainContent$ucViewControl_IntegratedFedWatchTool$uccv$lvMeetings$ctrl0$lbMeeting','')
javascript:__doPostBack('ctl00$MainContent$ucViewControl_IntegratedFedWatchTool$uccv$lvMeetings$ctrl1$lbMeeting','')
javascript:__doPostBack('ctl00$MainContent$ucViewControl_IntegratedFedWatchTool$uccv$lvMeetings$ctrl2$lbMeeting','')
javascript:__doPostBack('ctl00$MainContent$ucViewControl_IntegratedFedWatchTool$uccv$lvMeetings$ctrl3$lbMeeting','')
javascript:__doPostBack('ctl00$MainContent$ucViewControl_IntegratedFedWatchTool$uccv$lvMeetings$ctrl4$lbMeeting','')
javascript:__doPostBack('ctl00$MainContent$ucViewControl_IntegratedFedWatchTool$uccv$lvMeetings$ctrl5$lbMeeting','')
javascript:__doPostBack('ctl00$MainContent$ucViewControl_IntegratedFedWatchTool$uccv$lvMeetings$ctrl6$lbMeeting','')

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

 

 

 

Edited by oemript

Share this post


Link to post
Share on other sites
2 hours ago, oemript said:

I would like to know on how to click specific tabs in order to retrieve data for different months.  

Do you have any suggestions?

You should be able to use the same technique you quoted above. Navigate to the page and then to the actual frame location. From there, you shouldn't have any issues with clicking the desired link.

Share this post


Link to post
Share on other sites
Posted (edited)

Referring to following coding, within the same Frame, there is no specific name to locate following coding.

javascript:__doPostBack('ctl00$MainContent$ucViewControl_IntegratedFedWatchTool$uccv$lvMeetings$ctrl1$lbMeeting','')

The closer related location is this coding <div id="MainContent_pnlContrainer">, but I don't know on how to relate clicking to specific tab.

Do you have any suggestions on how to call above script and click tab? so it would display information on 19 Jun 19.
Thanks, to everyone very much for any suggestions (^v^)

FOMC3.png

Edited by oemript

Share this post


Link to post
Share on other sites

You can use the id of the tab directly with something like this :

$oTag = _IEGetObjById ($oIE, "ctl00_MainContent_ucViewControl_IntegratedFedWatchTool_uccv_lvMeetings_ctrl1_lbMeeting")
_IEAction ($oTag, "click")
_IELoadWait ($oIE)

Each tab has its own number if you look carefully the ids...

Share this post


Link to post
Share on other sites

Referring to following coding, I would like to know on what following do, since I already select 18 Sep 19 Tab, but the $oTable still retrieve data from 1 May 19 tab

Do you have any suggestions on why IETableGetCollection do not able to update content?
Thanks, to everyone very much for any suggestions (^v^)

 

#include <IE.au3>
#include <array.au3>

$oIE = _IECreate("https://www.cmegroup.com/trading/interest-rates/countdown-to-fomc.html")
_IENavigate($oIE, "https://cmegroup-tools.quikstrike.net/User/QuikStrikeView.aspx?viewitemid=IntegratedFedWatchTool")

$oTag = _IEGetObjById ($oIE, "ctl00_MainContent_ucViewControl_IntegratedFedWatchTool_uccv_lvMeetings_ctrl3_lbMeeting")
_IEAction ($oTag, "click")
_IELoadWait ($oIE)

$oTable = _IETableGetCollection($oIE, 4) ; What does it do?
$aData = _IETableWriteToArray($oTable)
_ArrayDisplay($aData)

 

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

×
×
  • Create New...