olzs00 Posted December 5, 2019 Share Posted December 5, 2019 On my webpage there are several div-tags and there are several tables. None of them have an id or a name. The order of the divs and tables are not fixed which means I cant use _IETableGetCollection() The table I'm trying to get data form is always the first table after the div-tag with .innertext="This is a unique innertext for a div-tagg". See example code below. <div class="content_bold">This is a unique innertext for a div-tagg</div> <table class="area_EEEEEE" width="400"> <tr class="componentHeaderSmall"> <td>Value1</td> </tr> <tr class="adminHeader"> <td>Value2</td> </tr> </table> How do I find the correct table and how do I write down the value for each td.innertext from the table? I guess need something like this $tag = _IETagNameGetCollection($oIE, "div") For $tags In $tag If $tags.innertext="This is a unique innertext for a div-tagg" Then ;Get The First Table ;Write Down Each td.innertext inside the table in my Excelfile useing _Excel_RangeWrite() Next Any ideas? Link to comment Share on other sites More sharing options...
Danp2 Posted December 5, 2019 Share Posted December 5, 2019 Once you've found the correct Div element, try passing it to _IETableGetCollection in place of $oIE. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Nine Posted December 5, 2019 Share Posted December 5, 2019 May not work because the div is not embedding the table. Try using $tags.nextElementSibling to get the table object. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
olzs00 Posted January 30, 2020 Author Share Posted January 30, 2020 Sorry for a very late response but thanks to you both for tip on how I can solve it. I'm pretty sure the code can be written in a more efficient way, but I solved it with the following code $tag = _IETagNameGetCollection($oIE, "div") For $tags In $tag If $tags.innertext="This is a unique innertext for a div-tagg" Then ;Find the right table and thats the one after this div-tag Local $oTable = $tags.NextElementSibling ExitLoop EndIf Next Local $aTableData = _IETableWriteToArray($oTable, True) ;true=create a table more like the one on the web-page If $iGetSomeData = 1 Then _Excel_RangeWrite($oWorkbook, Default, $aTableData[1][1], $ColumnToWriteInfo1In&$i) _Excel_RangeWrite($oWorkbook, Default, $aTableData[2][1], $ColumnToWriteInfo2In&$i) _Excel_RangeWrite($oWorkbook, Default, $aTableData[3][1], $ColumnToWriteInfo3In&$i) _Excel_RangeWrite($oWorkbook, Default, $aTableData[5][1], $ColumnToWriteInfo4In&$i) _Excel_RangeWrite($oWorkbook, Default, $aTableData[6][1], $ColumnToWriteInfo5In&$i) EndIf In the code above I know that there will always be 6 values that I want to write down. I had another similar problem with at table that I dont know the number of cells in. I solved that with the following code $tag = _IETagNameGetCollection($oIE, "div") For $tags In $tag If $tags.innertext="This is the div-tag above the table" Then ;Find the right table and thats the one after this div-tag Local $oTableChannelPackages = $tags.NextElementSibling ExitLoop EndIf Next Local $aTableDataChannelPackages = _IETableWriteToArray($oTableChannelPackages, True) ;true=create a table more like the one on the web page Local $iNumberOfChannelPackages = UBound($aTableDataChannelPackages, $UBOUND_ROWS) For $iNumberOfColumns = 0 to $iNumberOfChannelPackages-1 _Excel_RangeWrite($oWorkbook, Default, $aTableDataChannelPackages[$iNumberOfColumns][0], $ColumnToWriteInfo8In&$i) $i = $i+1 Next If someone has a tip how I can re-write the code to make it more efficient you are more than welcome to write a comment. Thanks in advance 🙂 Link to comment Share on other sites More sharing options...
Danp2 Posted January 30, 2020 Share Posted January 30, 2020 A few suggestions -- Move the variable declaration of $oTable outside of for For loop. That will avoid the scenario where the variable doesn't exist because the div element wasn't found Don't blindly continue after the For loop. Check the value of $oTable using IsObj() first Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Nine Posted January 30, 2020 Share Posted January 30, 2020 Agree with Danp2. Also I do not see where $i is declared nor set to 1. You could use $iNumberOfColumns+1 instead of $i. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now