Goodwin
Goodwin

Reputation: 183

iMacro Multiple Links In Div

In iMacro I am trying to extract multiple links inside a div, go to them and download the page. I currently have the multiple tabs and downloading good but don't know how to extract multiple links and go to each one. The html looks something like this:

<div class="bodyTXT">
  <table class="bodytxt">
    <tr valign="top">
      <td>
        <table class="bodyTXT">
          <tr valign="top">
            <td>
              <!--Has two links inside :(-->
              <a href="a/relative/link/add/domain/before">
                <a href="example.com" target="_blank">example.com</a>
            </td>
          </tr>
        </table>

        <table class="bodyTXT">
          <tr valign="top">
            <td>
              <!--Has two links inside :(-->
              <a href="a/different/relative/link/add/domain/before">
                <a href="another-example.com" target="_blank">another-example.com</a>
            </td>
          </tr>
        </table>
      </td>
  </table>
</div>

Upvotes: 0

Views: 586

Answers (1)

Shugar
Shugar

Reputation: 5299

As a more universal solution I can suggest this code:

SET startLoop 1
SET !EXTRACT_TEST_POPUP NO
TAG POS=1 TYPE=TABLE ATTR=CLASS:bodyTXT EXTRACT=HTM
SET maxLoop EVAL("'{{!EXTRACT}}'.match(/ href=/g).length;")
SET !LOOP EVAL(1-{{maxLoop}}+{{startLoop}})
SET normLoop EVAL({{!LOOP}}+{{maxLoop}}-1)

TAG POS=R-1 TYPE=* ATTR=* EXTRACT=TXT
SET !EXTRACT NULL
TAG POS=R{{normLoop}} TYPE=A ATTR=* EXTRACT=HREF

'PROMPT {{!EXTRACT}}



You can try to apply relative positioning as follows:

TAG POS=3 TYPE=TABLE ATTR=CLASS:bodyTXT
TAG POS=R-2 TYPE=A ATTR=* EXTRACT=HREF
TAG POS=R2 TYPE=A ATTR=* EXTRACT=HREF
TAG POS=R-1 TYPE=A ATTR=* EXTRACT=HREF
TAG POS=R2 TYPE=A ATTR=* EXTRACT=HREF

(Pay attention to the order of extracts if needed.)

Upvotes: 2

Related Questions