Jump to content

[Solved] _IETagNameGetCollection for div - tr - td in a table

Recommended Posts


Hi All, 

I'm using an online translator for Spanish in which you give the verb and website gives the conjugations. The website I'm using is: http://www.spanishdict.com/conjugate/tener where "tener" means "to have" in English. 

In the screenshot, you can see the present tense (5 yellow highlighted items) and the imperfects (5 blue boxes). I don't need to get the translation for "vosotros", so I didn't make any color on that row. I'm trying to get these 10 translations to be written on the output for my code. But my code is so simple (because I couldn't go into the div / tr / td): 

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

Local $sSpanishWord = "tener" ;to have
;Local $sSpanishWord = "abrir" ;to open
Local $oIE = _IECreate ("http://www.spanishdict.com/conjugate/" & $sSpanishWord)

;== Try using _IETagNameAllGetCollection
Local $oElements = _IETagNameAllGetCollection($oIE)
For $oElement In $oElements
    If $oElement.id Then
        ConsoleWrite("Tagname: " & $oElement.tagname & @CRLF & "id: " & $oElement.id & @CRLF & "innerText: " & $oElement.innerText & @CRLF & @CRLF)

;== Try using _IETagNameGetCollection
Local $sTable
Local $oTableCells
Local $oTableRows = _IETagNameGetCollection($oIE, "tr")
For $oTableRow In $oTableRows
    $sTable = ""
    $oTableCells = _IETagNameGetCollection($oTableRow, "td")
    ;I don't know how to continue from here on

I used the IE to find out the tr / td stuff, but I think I'm lost. 

P.S: The verb "tener" can be difficult, because it has red letters because of irregular. The verb "abrir" can be much easier, because it's a regular verb. 

Conjugation Example.png

HTML View.png

Edited by taylansan
Modified the title as solved


Share this post

Link to post
Share on other sites

? are you trying to capture data from the whole table?
if so then you can easily get the table content using the  _IETableWriteToArray() function

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

Local $sSpanishWord = "tener" ;to have
Local $oIE = _IECreate ("http://www.spanishdict.com/conjugate/" & $sSpanishWord)

Local $oTable = _IETableGetCollection($oIE, 2)
Local $aTableData = _IETableWriteToArray($oTable,  True)



  • Like 1

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post

Link to post
Share on other sites

This is exactly what I was looking for.

Thank you very much :)


Share this post

Link to post
Share on other sites
On 3/21/2017 at 8:20 PM, Chimp said:

Local $oTable = _IETableGetCollection($oIE, 2)

One more question: 

I have checked this page had 7 tables (the first two tables are empty, the rest are filled with information). How exactly did you know to search the 3rd table? I could only search one by one. What's the logic behind to check on the 3rd one? 

2. Actually I have other question (similar to the first one). Below is the example in the help files for the function _IEFormElementGetCollection. How exactly it's known to check ($oForm, 4)? Why not other number? How can I know this? 

; Get a reference to a specific form element by 0-based index.
; In this case, submit a query to the Google search engine

#include <IE.au3>

Local $oIE = _IECreate("http://www.google.com")
Local $oForm = _IEFormGetCollection($oIE, 0)
Local $oQuery = _IEFormElementGetCollection($oForm, 4)
_IEFormElementSetValue($oQuery, "AutoIt IE.au3")


Edited by taylansan


Share this post

Link to post
Share on other sites

Hi @taylansan,

I think you could analyze the html of the page, but maybe the quickest way is the search one by one.
Some time ago I wrote a function to extract tables from raw html (without the need to make use of a browser), and to test it I also wrote an example script that allows to browse all tables in an html page, If you want to test it below there is the link, you have to use the second script (the example script), from that script you can enter the link of your page. It show all the tables in the page and allows you to visually chose the tables one by one. maybe it can be of use to search your wanted table:


  • Like 1

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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

  • Similar Content

    • Faalamva
      By Faalamva
      I'm using the IE.au3 library to parse elements in a webpage and get their (x,y) coordinates.
      Main commands I'm using are :         
      $oIE = _IECreate($myWebPage) $oElements = _IETagNameGetCollection($oIE, "label") $windowleft = $oIE.document.parentwindow.screenLeft $windowtop = $oIE.document.parentwindow.screenTop $oElementPosX = $windowleft + _IEfindPosX($oElement) $oElementPosY = $windowtop + _IEfindPosY($oElement) Now things become a bit tricky when i simulate a scroll in my webpage :
      $oIE.document.parentwindow.scroll(0, $myScrollY) Because once this is done, the coordinates of the elements are still what they were before the scroll.
      I can manage this problem by keeping track of the number of pixels I have scrolled, and compute the new "real" ($oElementPosX, $oElementPosY).
      But I'm pretty sure there's a more efficient / more elegant way to do it.
      What's more in some situations, when I click some controls in the webpage, the webpage adds new elements and shifts the controls below by a random number of pixel, so my workaround can't be used...
      So here's my question : Is there a way to "refresh" the calculation of label coordinates ($oElementPosX, $oElementPosY) after a scroll ?
      Thank you !
      EDIT : I forgot to post the _IEfindPosX and _IEfindPosY functions (found somewhere on this forum) :
      Func _IEfindPosX($o_object) Local $curleft = 0 Local $parent = $o_object If IsObj($parent) Then While IsObj($parent) $curleft += $parent.offsetLeft $parent = $parent.offsetParent WEnd Else Local $objx = $o_object.x If IsObj($objx) Then $curleft += $objx EndIf Return $curleft EndFunc Func _IEfindPosY($o_object) Local $curtop = 0 Local $parent = $o_object If IsObj($parent) Then While IsObj($parent) $curtop += $parent.offsetTop $parent = $parent.offsetParent WEnd Else Local $objy = $o_object.y If IsObj($objy) Then $curtop += $objy EndIf Return $curtop EndFunc  
    • TimothyGirard
      By TimothyGirard
      I'm trying to create an autoPop tool for AliExpress. When I get to their address page, there are a number of input fields. There are also two drop downs. One is for the country and, depending on what you select, the other dropdown appears with city names or, a standard input box is visible to add a city (See the images). So if I select "United States" the other dropdown is visible with all the states. If I select "France", the input box is visible to enter a French city. Seems cool enough but I'm really struggling trying to get this to work.
      This is my test code to work all this out:
      #include <MsgBoxConstants.au3> #include <IE.au3> Local $StartPos Local $oIE = _IECreate("https://shoppingcart.aliexpress.com/order/confirm_order.htm?objectId=1792065272&from=aliexpress&countryCode=US&shippingCompany=EMS&provinceCode=&cityCode=&promiseId=&itemCondition=&=556&aeOrderFrom=main_detail&skuAttr=&quantity=1") If @error Then Exit MsgBox(16, "openURL Error", @CRLF & "@error = " & @error & ", @extended = " & @extended) ;If $bVerbose == true Then MsgBox(0, "openURL", "IECreate Object Created") ;Get the Collections $oInputs = _IETagNameGetCollection($oIE, "input"); Input Fields $oSelects = _IETagNameGetCollection($oIE, "select"); Select Fields ;Loop through the Selects For $oSelect In $oSelects If $oSelect.name = "country" Then _IEFormElementOptionSelect($oSelect, "France", 1, "byText",1) Next ;Loop through the inputs For $oInput In $oInputs If $oInput.name = "email" Then $oInput.Value = "test@test.com" If $oInput.name = "contactPerson" Then $oInput.Value = "My Full Name" If $oInput.name = "address" Then $oInput.Value = "123 Anystreet" If $oInput.name = "address2" Then $oInput.Value = "NA" If $oInput.name = "province" Then MsgBox(0, "","$oInput.name = " & $oInput.name &@CRLF &"$oInput.style = " & $oInput.style &@CRLF &"$oInput.type = " & $oInput.type&@CRLF &"$oInput.maxLength = " & $oInput.maxlength) $oInput.Value = "FrenchyLand" EndIf If $oInput.name = "city" Then $oInput.Value = "AnyTown" If $oInput.name = "zip" Then $oInput.Value = "12345" If $oInput.name = "mobileNo" Then $oInput.Value = "1-415-555-1212" Next So I open the page on AliExpress and get an   "input" collection and a "select" Collection
      I first loop through the Selects until I find "country" and then select "France"
      I then loop through all the inputs and put the information in the correct inputs.
      When the country is one that AliExpress knows the states or provinces for,  they swap Styles between the input box and the dropdown  to either "display: inline-block;" or "display: none;" which hides one, or the other (See the AliExpDOM Image).
      Problem #1: When I use the "_IEFormElementOptionSelect($oSelect, "France", 1, "byText",1)" To make the dropdown selection, It selects it but does not invoke the widget to change the second dropdown to an input box.
      Problem #2: I thought a possible solution would be to read the Style of the input box and based on the value, either place text in the input box or go to the dropdown and make a selection. I can't seem to read the Style attribute from the collection ie: $oInput.style returns nothing.
      Any help here would be greatly appreciated. If I figure out a solution before and answer here, I will publish it here for anyone else who might be struggling with these kinds of things

    • vladtsepesh
      By vladtsepesh
      Hi all,
      I got the need of crawling all the label tag contained within a div element, and then inspecting one by one looking for a specified content
      Local $reportForm=_IEFormGetObjByName($oIE,"ui_form") If @error Then ConsoleWrite('_IEFormGetObjByName @error = ' & @error & ' @extended = ' & @extended & @CRLF) EndIf Local $divTagSites = _IEGetObjById($reportForm, "divElementId") If @error Then ConsoleWrite('_IEGetObjById for @error = ' & @error & ' @extended = ' & @extended & @CRLF) EndIf Local $divLabels = _IETagNameGetCollection($divTagSites, "label") If @error Then ConsoleWrite('_IETagNameGetCollection for label @error = ' & @error & ' @extended = ' & @extended & @CRLF) EndIf ConsoleWrite('_IETagNameGetCollection @extended = ' & @extended & @CRLF) For $divLabel In $divLabels ConsoleWrite($divLabel.for & @CRLF) Next the html looks like the following
      <div id="divElementId"> <td nowrap="nowrap"> <span> <input id="divElementId_ctl01" type="checkbox" name="divElementId$ctl01" onclick="some JavaScript stuff" /> <label for="divElementId_ctl01_ctl01">ele-1000002 [1000002]</label> </span> </td> </div> what I'd like to perform is to access the label element text ele-1000002 [1000002] comparing to a variable and then check the corresponding checkbox.
      What I miss is the step: accessing the text inside the label tag.
      PS: searching through the forum I found out only method based on analyzing the whole html page.
    • talkfoodtalk
      By talkfoodtalk
      HI,   I cannot work out how to connect to the input box on this link:   https://cms.bskyb.2wire.com/manage/login   My usual method is in my code but it does not seem to find the elements I need to connect with. I can see that "text" and "password" are on the page but im confused about putting input to it.   Can someone point me in the right direction?         Kind Regards Dave #include <IE.au3> #include <MsgBoxConstants.au3> $PACE = _IEAttach("https://cms.bskyb.2wire.com/manage/login", "url") If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "PACE not attached") $PACE =_IECreate("https://cms.bskyb.2wire.com/manage/login") EndIf $colForms = _IEFormGetCollection ($PACE ) For $oForm In $colForms $colElements = _IETagNameAllGetCollection ( $oForm ) For $oElement In $colElements If StringInStr ( $oElement.getAttribute ( "tkPid", 2 ), "PID19" ) <> 0 Then MsgBox(0, "Result", "Success") _IEFormElementSetValue($oElement, "username") ;~ _IEAction ( $oElement, "click" ) Else EndIf If StringInStr ( $oElement.getAttribute ( "__eventBits=", 2 ), "7409" ) <> 0 Then MsgBox(0, "Result", "Success") _IEFormElementSetValue($oElement, "password") ;~ _IEAction ( $oElement, "click" ) Else EndIf Next Next Local $oInputs = _IETagNameGetCollection($PACE, "input") Local $sTxt = "" For $oInput In $oInputs $sTxt &= $oInput.type & @CRLF if $oInput.type = "text" Then EndIf Next MsgBox($MB_SYSTEMMODAL, "Form Inqput Type", "Form: " & $oInput.form.name & @CRLF & @CRLF & " Types :" & @CRLF & $sTxt)    
    • 6105
      By 6105
      I can't find solution to check if object have variable or not, i have 2 variables in object, i use:

      $oIE = _IECreate('D:\Dropbox\Projects\au3\IE_Builder\test.html') $oInputs = _IETagNameGetCollection($oIE, "form") For $oInput In $oInputs $d = $oInput.name If $d = 0 then ConsoleWrite("Form: " & $d & @CRLF) Next
      And result is:

      Form: 0 Form: d3e8f5e3ba12
      I have tried many solutions, but no one works.... pls help. i can't separate this variables..