title: HTML Table Scraping – Getting href attribute from a column
body: <p>Here is a simple and valid HTML table (<a href="http://five-kings.co.uk/question/table.html" rel="nofollow noreferrer">live demo</a>):</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html id="world_presidents" xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"&gt;
      &lt;head&gt;
          &lt;meta charset='utf-8' /&gt;
          &lt;style&gt;
              table, td, th {
                  border: 1px solid grey;
              }
          &lt;/style&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;th&gt;Name&lt;/th&gt;
                  &lt;th&gt;Took office&lt;/th&gt;
                  &lt;th&gt;Resources&lt;/th&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;a href="http://en.wikipedia.org/wiki/George_Washington"&gt;George Washington&lt;/a&gt;&lt;/td&gt;
  
                  &lt;td&gt;1789&lt;/td&gt;
                  &lt;td&gt;&lt;a href="http://books.google.co.uk/books?id=t1pQ4YG-TDIC&amp;pg=PA148&amp;dq=#v=onepage&amp;q=&amp;f=false"  title="encyclopedia"&gt;Encyclopedia&lt;/a&gt;(&lt;a href="http://constitutioncenter.org/media/audio/ron_chernow_10-18-10_(64).mp3"  title="Subresource"&gt;Sub Resource&lt;/a&gt;)&lt;br&gt;
                  &lt;a href="http://en.wikipedia.org/wiki/George_Washington#CITEREFParry1991"  title="parry"&gt;Parry 1991&lt;/a&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;John Adams&lt;/td&gt;
                  &lt;td&gt;1797&lt;/td&gt;
                  &lt;td&gt;&lt;a href="http://www.adherents.com/people/pa/John_Adams.html"  title="Adherents.com"&gt;Adherents.com&lt;/a&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Thomas Jefferson&lt;/td&gt;
                  &lt;td&gt;1801&lt;/td&gt;
                  &lt;td&gt;&lt;a href="http://books.google.co.uk/books?id=qkTPAAAAMAAJ&amp;redir_esc=y"  title="Government Printing Office"&gt;Government Printing Office&lt;/a&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;James Madison&lt;/td&gt;
                  &lt;td&gt;1809&lt;/td&gt;
                  &lt;td&gt;&lt;a href="http://www.loa.org/volume.jsp?RequestID=16&amp;section=toc"  title="Library of America"&gt;Library of America&lt;/a&gt;&lt;br&gt;
                  &lt;a href="http://quod.lib.umich.edu/cgi/t/text/text-idx?c=acls;cc=acls;view=toc;idno=HEB00509.0001.001"  title="Federal Republic"&gt;Federal Republic&lt;/a&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;James Monroe&lt;/td&gt;
                  &lt;td&gt;1817&lt;/td&gt;
                  &lt;td&gt;&lt;a href="https://rads.stackoverflow.com/amzn/click/com/0813912660" rel="nofollow noreferrer"  title="scholarly biography"&gt;scholarly biography&lt;/a&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;John Quincy Adams&lt;/td&gt;
                  &lt;td&gt;1825&lt;/td&gt;
                  &lt;td&gt;&lt;a href="http://www.common-place.org/vol-09/no-01/adams/"  title="Common-Place"&gt;Common-Place&lt;/a&gt;&amp;nbsp;(&lt;a href="http://dx.doi.org/10.1111%2F1467-7709.00049"  title="Diplomatic History"&gt;Aditional - Diplomatic History&lt;/a&gt;)&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Andrew Jackson&lt;/td&gt;
                  &lt;td&gt;1829&lt;/td&gt;
                  &lt;td&gt;&lt;a href="http://statelibrary.dcr.state.nc.us/nc/bio/public/jackson.htm"  title="Information Services Branch"&gt;Information Services Branch&lt;/a&gt;&amp;nbsp;(&lt;a href="http://www.discovernorthernireland.com/product.aspx?ProductID=2801"  title="Tourist Board"&gt;Tourist Board&lt;/a&gt;)&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Martin Van Buren&lt;/td&gt;
                  &lt;td&gt;1837&lt;/td&gt;
                  &lt;td&gt;&lt;a href="http://en.wikipedia.org/wiki/Holmes_Alexander"  title="The American Talleyrand"&gt;The American Talleyrand&lt;/a&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I am trying to get all the data from columns so I can insert it into database. I am stuck on the third column as I am trying to get all the links from 'href' attribute. I have created the code below that works with first and second column but I can't find a way to change it so it will display all the links from third column.</p>
  
  <pre><code>&lt;?php 
  
  require_once 'simple_html_dom.php'; 
  $html = new simple_html_dom(); 
  $html = file_get_html('table.html'); 
  
  //engine 
  //go through table and find href attributes
  echo"&lt;p&gt;Presidents&lt;/p&gt;"; 
  foreach($html-&gt;find('//*[@id="world_presidents"]/body/table/tbody/tr/') as $row) { 
      $presidentsLink = $row-&gt;find('a', 2); 
      if(!empty($presidentsLink)){ 
          echo $presidentsLink-&gt;href . "&lt;br&gt;"; 
      } 
  }
  
  ?&gt; 
  </code></pre>
  
  <p>Right now it only display one link instead of 13 (<a href="http://five-kings.co.uk/question/php_scraping_V6.php" rel="nofollow noreferrer">live demo</a>). </p>
  
  <p>Simply speaking:</p>
  
  <ul>
  <li>I am using Simple HTML DOM Parser to get content from html table</li>
  <li>I am not able to change the thml table</li>
  <li>My problem is to get all the href attributes from third column and display them</li>
  </ul>
  
  <p>I would be grateful for any help.</p>