Extract ALL child div's classes data with iMacros to Excel

356 views Asked by At

Scenario :** DIV with multiple child. I wished to extract all the child data with iMacros into Excel. All my required data is contained in child <tr class="odd", <tr class="even", <tr class="odd", and so on...

Each class="odd" or class="even" consist of 1 line of data to be extracted. However, class="odd" consist of unique individual column data eg. "rightcelltd 1cell".

Here is the html body part:

<div class="dataTables_scrollBody" style="position: relative; overflow: auto; max-height: 310px; height: 310px; width: 100%;">

  <table id="opt_montage_table" class="montage_table dataTable" style="width: 100%;">

    
<tbody>
      <tr class="odd">
          <td class="rightcelltd 1cell">
          <td class="rightcelltd 2cell">
          <td class="rightcelltd 3cell">
      <tr class="even">
          <td class="rightcelltd 1cell">
          <td class="rightcelltd 2cell">
          <td class="rightcelltd 3cell">
      <tr class="odd">
          <td class="rightcelltd 1cell">
          <td class="rightcelltd 2cell">
          <td class="rightcelltd 3cell">
      <tr class="even">
      <tr class="odd">
      <tr class="even">
      <tr class="odd">
      <tr class="even">

enter image description here

I've tried the followings:

  1. TAG POS=5 TYPE=DIV ATTR=CLASS:"dataTables_scrollBody" EXTRACT=TXT
  2. TAG POS=5 TYPE=TABLE ATTR=CLASS:"montage_table dataTable" EXTRACT=TXT
  3. TAG POS=5 TYPE=TABLE ATTR=CLASS:"opt_montage_table" EXTRACT=TXT
  4. TAG POS=5 TYPE=TABLE ATTR=CLASS:"montage_table dataTable" EXTRACT=TXT
  5. TAG POS=5 TYPE=DIV ATTR=CLASS:"montage_table dataTable" EXTRACT=TXT

Unfortunately, they don't work and result in a #enaf#.

Hope some Guru's able to provide some advise or solution to the above. Thanking you in advance for your kindness and time.

1

There are 1 answers

10
chivracq On

Some Tech Info is missing from your Question as you didn't read the Tag Wiki, but OK..., I can still answer it...

EDIT/Update (Temp): (2022-08-28/29)
Status: Waiting for @OP to create the Parallel Thread (on the iMacros Forum).
My Answer was "supposed" to be some "easy"/straightforward Solution to @OP's Qt (Question), but apparently not (see the Comments), Thread is now going into some "Debug/Troubleshooting"-Mode, not very suitable for 'SO' as I can't really post "mini-Scripts" to try/test in Comments, => we'll be doing the Troubleshooting part on the iMacros Forum ('Data-Extraction' Sub-Forum, => the 1st/last Thread there I reckon, with the same Thread Title.)

[Mod and "Tech Guru" on that Forum, so I have more "Power(s)" about the Content, (and Data-Extraction is my "Specialty", oops..!), and I'll "later" update my Answer (here) with the "final" (working) Solution... (Might take a few days though, depending on if I can do "the Testing" myself, or if only @OP can do it, because Site behind L&P etc...)]


DIV with multiple child [elements]. I wished to extract all the child data...

=> "DIV" + "multiple child [elements]" + "child data" are a bit irrelevant... Rather important is that all the Data you want to extract is structured/displayed in a Table (TABLE), containing Rows (TRs), no Header, and each Row contains 3 Cells (TDs).

The number of Rows is probably dynamic, and as you actually want to extract all the Rows/all the Cells, the "easiest" Implementation would be to extract the whole Data in just one EXTRACT, => at the TABLE Level, like in:

TAG POS=1 TYPE=TABLE ATTR=CLASS:"montage_table dataTable" EXTRACT=TXT

... which is actually very close to the TAG POS=5 TYPE=TABLE ATTR=CLASS:"montage_table dataTable" EXTRACT=TXT that you had tried... (Attempts '2' + '4'.)


Also good would be to extract the same TABLE using its ID (instead of CLASS):

TAG POS=1 TYPE=TABLE ATTR=ID:"opt_montage_table" EXTRACT=TXT

... which is possibly what you tried in Attempt '3'...

I "suppose" both the CLASS and the ID for that Table will be unique on the Page, => POS=1, you might need to "adjust" to POS=2 etc..., if there are several Tables with the same 'Attributes' on the same Page...

(Not tested, I would need the URL of the Page, your Code Snippet is not runable... (Probably misses some HTML + BODY Elements, if pure HTML Snippets "work", I don't know, I've never used Snippets for the Tag...) ... Oh...!, maybe it "works" actually, but all HTML Elements don't contain any (visible/extractable) (TXT) Data at all, ah-ah...!, => the Snippet Area appears all Blank, tja...! But nope, won't work, all closing HTML Tags are missing also...)