title: Simple HTML DOM: Notice->Trying to get property of non-object
body: <p>I am getting an php notice when using simple html dom to scrape a website. There are 2 notices displayed and everything rendered underneath looks perfect when using the print_r function to display it.</p>
  
  <p>The website table structure is as follows:</p>
  
  <pre><code>    &lt;table class=data schedTbl&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;DATA&lt;/th&gt;
                  &lt;th&gt;DATA&lt;/th&gt;
                  &lt;th&gt;DATA&lt;/th&gt;
                  etc....
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;div class="class1"&gt;DATA&lt;/div&gt;
                      &lt;div class="class2"&gt;SAME DATA AS PREVIOUS DIV&lt;/div&gt;
                  &lt;/td&gt;
                  &lt;td&gt;DATA&lt;/td&gt;
                  &lt;td&gt;DATA&lt;/td&gt;
                  etc....
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;div class="class1"&gt;DATA&lt;/div&gt;
                      &lt;div class="class2"&gt;SAME DATA AS PREVIOUS DIV&lt;/div&gt;
                  &lt;/td&gt;
                  &lt;td&gt;DATA&lt;/td&gt;
                  &lt;td&gt;DATA&lt;/td&gt;
                  etc....
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;div class="class1"&gt;DATA&lt;/div&gt;
                      &lt;div class="class2"&gt;SAME DATA AS PREVIOUS DIV&lt;/div&gt;
                  &lt;/td&gt;
                  &lt;td&gt;DATA&lt;/td&gt;
                  &lt;td&gt;DATA&lt;/td&gt;
                  etc....
              &lt;/tr&gt;
              etc....
          &lt;/tbody&gt;
      &lt;/table&gt;
  </code></pre>
  
  <p>The code below is used to find all tr in table[class=data schedTbl]. I have a tbody selector in there, but it seems to pay no attention to this selector as it still selects the tr in the thead.</p>
  
  <pre><code>    include('simple_html_dom.php');
  
      $articles = array();
  
      getArticles('www.somesite.com');
  
      function getArticles($page) {
           global $articles;
  
           $html = new simple_html_dom();
           $html-&gt;load_file($page);
  
           $items = $html-&gt;find('table[class=data schedTbl] tbody tr');  
  
           foreach($items as $post) {
  
               $articles[] = array($post-&gt;children(0)-&gt;first_child(0)-&gt;plaintext,//0 -- GAME DATE
                          $post-&gt;children(1)-&gt;plaintext,//1 -- AWAY TEAM
                          $post-&gt;children(2)-&gt;plaintext);//2 -- HOME TEAM
  
           }
  
      }
  </code></pre>
  
  <p>So, I believe notices come from the tr in the thead because I am calling on the first child of the first td which only has one record. The reason for two is there is actually two tables with the same data structure in the body.</p>
  
  <p>Again, I believe there are 2 ways of solving this:</p>
  
  <p>1) PROBABLY THE EASIEST (fix the find selector so the TBODY works and only selects the tds within the tbodies)</p>
  
  <p>2) Figure out a way to not do the first_child filter when it is not needed?</p>
  
  <p>Please let me know if you would like a snapshot of the print_r($articles) output I am receiving.</p>
  
  <p>Thanks in advance for any help provided!</p>
  
  <p>Sincerely,</p>
  
  <p>Bill C. </p>