title: XPath for td/th based on tr count
body: <p>Using XPath to webscrape. </p>
  
  <p>The structure is: </p>
  
  <pre><code>&lt;table&gt;
    &lt;tbody&gt;
       &lt;tr&gt;
          &lt;th&gt;
          &lt;td&gt;
  </code></pre>
  
  <p>but one of those tr has contains just one th or one td.</p>
  
  <pre><code>&lt;table&gt;
        &lt;tbody&gt;
           &lt;tr&gt;
              &lt;th&gt;
  </code></pre>
  
  <p>So I just want to scrape if <code>TR</code> contains two tags inside it. I am giving the path </p>
  
  <pre><code> $route = $path-&gt;query("//table[count(tr) &gt; 1]//tr/th");
  </code></pre>
  
  <p>or</p>
  
  <pre><code> $route = $path-&gt;query("//table[count(tr) &gt; 1]//tr/td");
  </code></pre>
  
  <p>But it's not working. </p>
  
  <p>I am giving the orjinal table's links here. First table's last two TR is has just one TD. That is causing the problem. And 2nd or 3rd table has same issue as well.</p>
  
  <p><a href="https://www.daiwahouse.co.jp/mansion/kanto/tokyo/y35/gaiyo.html" rel="nofollow noreferrer">https://www.daiwahouse.co.jp/mansion/kanto/tokyo/y35/gaiyo.html</a></p>
  
  <pre><code>      $route = $path-&gt;query("//tr[count(*) &gt;= 2]/th");
        foreach ($route as $th){
            $property[] = trim($th-&gt;nodeValue);
        }
  
        $route = $path-&gt;query("//tr[count(*) &gt;= 2]/td");
        foreach ($route as $td){
            $value[] = trim($td-&gt;nodeValue);
        }
  </code></pre>
  
  <p>I am trying to select TH and TD at the same time. BUT if TR has contains one TD then it caunsing the problem. Because in the and TD count and TH count not same I am scraping more TD then the TH</p>