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)
;http://www.spanishdict.com/conjugate/tener
;http://www.spanishdict.com/conjugate/abrir

;== 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)
    EndIf
Next

;== 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
Next

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

TY.

Link to comment
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)

_ArrayDisplay($aTableData)

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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")
_IEFormSubmit($oForm)

 

Edited by taylansan

TY.

Link to comment
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.
P.S.
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:

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

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

×
×
  • Create New...