title: PHP / JS - HTML parsing - selector not working in PHP
body: <p>I'm using the Simple HTML DOM library on PHP, you can find this library here:
  <a href="http://simplehtmldom.sourceforge.net/" rel="nofollow noreferrer">Simple HTML DOM</a></p>
  
  <p>I'm also parsing HTML with Javascript, mainly to isolate the selectors I need.</p>
  
  <p>I first experiment parsing with Javascript (with querySelectorAll) and when it works I re-use the same selector with PHP Simple HTML DOM (with ->find).</p>
  
  <p>Let's take the following page to illustrate the issue: <a href="https://www.amazon.fr/s/ref=nb_sb_noss_2?__mk_fr_FR=%C3%85M%C3%85%C5%BD%C3%95%C3%91&amp;url=search-alias%3Daps&amp;field-keywords=GTX%201060&amp;rh=i%3Aaps%2Ck%3AGTX%201060" rel="nofollow noreferrer">Page from Amazon.fr</a></p>
  
  <pre><code>$html = file_get_html('PAGE URL FROM EXAMPLE ABOVE');
  $products = $html-&gt;find('.s-item-container');
  for ($z = 0 ; $z &lt; sizeof($products); $z++)
      {
          foreach($products[$z]-&gt;find('.a-row .a-spacing-none .s-access-detail-page') as $titles) 
              {
                  $title = $titles-&gt;plaintext;
              }
      }
  </code></pre>
  
  <p>This works perfectly fine, if I echo $title, I do get the right title. </p>
  
  <p>Now if I want to capture prices with this:</p>
  
  <pre><code>$products[$z]-&gt;find('div &gt; div.a-fixed-left-grid &gt; div &gt; div.a-fixed-left-grid-col.a-col-right &gt; div:nth-child(2) &gt; div.a-column.a-span7 &gt; div.a-row.a-spacing-none &gt; a &gt; span.a-size-base.a-color-price.s-price.a-text-bold');
  </code></pre>
  
  <p>If I display the content of $product[$z], I can see the selector I'm looking for, it's visible in the html but the find function doesn't find it. </p>
  
  <p>I had tried exactly the same thing in Javascript with:</p>
  
  <pre><code>document.querySelectorAll('div &gt; div.a-fixed-left-grid &gt; div &gt; div.a-fixed-left-grid-col.a-col-right &gt; div:nth-child(2) &gt; div.a-column.a-span7 &gt; div.a-row.a-spacing-none &gt; a &gt; span.a-size-base.a-color-price.s-price.a-text-bold');
  </code></pre>
  
  <p>And it works fine by returning this:</p>
  
  <p><a href="https://i.stack.imgur.com/NMGXU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NMGXU.png" alt="enter image description here"></a></p>
  
  <p>I don't understand why it happens because when it works in JS it works in PHP as well, this is the only example where it doesn't work and I don't see what's going wrong.</p>
  
  <p>Do you have any idea?</p>
  
  <p>Thanks !
  Laurent</p>
  
  <p>As requested here under, here is a dump: (sorry it's difficult to read)</p>
  
  <pre><code>&lt;div class="s-item-container"&gt;&lt;div class="a-fixed-left-grid"&gt;&lt;div class="a-fixed-left-grid-inner" style="padding-left:218px"&gt;&lt;div class="a-fixed-left-grid-col a-col-left" style="width:218px;margin-left:-218px;float:left;"&gt;&lt;div class="a-row"&gt;&lt;div aria-hidden="true" class="a-column a-span12 a-text-center"&gt;&lt;a class="a-link-normal a-text-normal" href="https://www.amazon.fr/MSI-GEFORCE-GTX-1060-3GT/dp/B01KHWOB78/ref=sr_1_18?ie=UTF8&amp;amp;qid=1533908456&amp;amp;sr=8-18&amp;amp;keywords=GTX+1060"&gt;&lt;img src="https://images-eu.ssl-images-amazon.com/images/I/518zhXqNWcL._AC_US218_.jpg" srcset="https://images-eu.ssl-images-amazon.com/images/I/518zhXqNWcL._AC_US218_.jpg 1x, https://images-eu.ssl-images-amazon.com/images/I/518zhXqNWcL._AC_US327_FMwebp_QL65_.jpg 1.5x, https://images-eu.ssl-images-amazon.com/images/I/518zhXqNWcL._AC_US436_FMwebp_QL65_.jpg 2x, https://images-eu.ssl-images-amazon.com/images/I/518zhXqNWcL._AC_US500_FMwebp_QL65_.jpg 2.2935x" width="218" height="218" alt="MSI GEFORCE GTX 1060 3GT OC Carte Graphique , 3 GB" class="s-access-image cfMarker" data-search-image-load&gt;&lt;/a&gt;&lt;div class="a-section a-spacing-none a-text-center"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="a-fixed-left-grid-col a-col-right" style="padding-left:2%;float:left;"&gt;&lt;div class="a-row a-spacing-small"&gt;&lt;div class="a-row a-spacing-none"&gt;&lt;a class="a-link-normal s-access-detail-page  s-color-twister-title-link a-text-normal" title="MSI GEFORCE GTX 1060 3GT OC Carte Graphique , 3 GB" href="https://www.amazon.fr/MSI-GEFORCE-GTX-1060-3GT/dp/B01KHWOB78/ref=sr_1_18?ie=UTF8&amp;amp;qid=1533908456&amp;amp;sr=8-18&amp;amp;keywords=GTX+1060"&gt;&lt;h2 data-attribute="MSI GEFORCE GTX 1060 3GT OC Carte Graphique , 3 GB" data-max-rows="0" class="a-size-medium s-inline  s-access-title  a-text-normal"&gt;MSI GEFORCE GTX 1060 3GT OC Carte Graphique , 3 GB&lt;/h2&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="a-row a-spacing-none"&gt;&lt;span class="a-size-small a-color-secondary"&gt;de &lt;/span&gt;&lt;span class="a-size-small a-color-secondary"&gt;MSI&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="a-row"&gt;&lt;div class="a-column a-span7"&gt;&lt;div class="a-row a-spacing-none"&gt;&lt;a class="a-link-normal a-text-normal" href="https://www.amazon.fr/MSI-GEFORCE-GTX-1060-3GT/dp/B01KHWOB78/ref=sr_1_18?ie=UTF8&amp;amp;qid=1533908456&amp;amp;sr=8-18&amp;amp;keywords=GTX+1060"&gt;&lt;span class="a-size-small a-color-secondary"&gt;&lt;/span&gt;&lt;span class="a-size-base a-color-price s-price a-text-bold"&gt;EUR 237,36&lt;/span&gt;&lt;/a&gt;&lt;span class="a-letter-space"&gt;&lt;/span&gt;&lt;span class="a-size-small a-color-secondary"&gt;+ EUR 14,90 Livraison&lt;/span&gt;&lt;/div&gt;&lt;div class="a-row a-spacing-mini"&gt;&lt;div class="a-row a-spacing-none"&gt;&lt;span class="a-size-small a-color-price"&gt;Plus que 4 ex. Commandez vite !&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="a-row a-spacing-mini"&gt;&lt;div class="a-row a-spacing-none"&gt;&lt;div class="a-row a-spacing-mini"&gt;&lt;/div&gt;&lt;span class="a-size-small a-color-secondary"&gt;Autres vendeurs sur Amazon&lt;/span&gt;&lt;/div&gt;&lt;div class="a-row a-spacing-none"&gt;&lt;a class="a-size-small a-link-normal a-text-normal" href="https://www.amazon.fr/gp/offer-listing/B01KHWOB78/ref=sr_1_18_olp?ie=UTF8&amp;amp;qid=1533908456&amp;amp;sr=8-18&amp;amp;keywords=GTX+1060"&gt;&lt;span class="a-color-secondary a-text-strike"&gt;&lt;/span&gt;&lt;span class="a-size-base a-color-price a-text-bold"&gt;EUR 176,54&lt;/span&gt;&lt;span class="a-letter-space"&gt;&lt;/span&gt;(28 d’occasion &amp; neufs)&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="a-column a-span5 a-span-last"&gt;&lt;div class="a-row a-spacing-mini"&gt;&lt;span name="B01KHWOB78"&gt;      &lt;span class="a-declarative" data-action="a-popover" data-a-popover="{&amp;quot;max-width&amp;quot;:&amp;quot;700&amp;quot;,&amp;quot;closeButton&amp;quot;:&amp;quot;false&amp;quot;,&amp;quot;position&amp;quot;:&amp;quot;triggerBottom&amp;quot;,&amp;quot;url&amp;quot;:&amp;quot;/review/widgets/average-customer-review/popover/ref=acr_search__popover?ie=UTF8&amp;amp;asin=B01KHWOB78&amp;amp;contextId=search&amp;amp;ref=acr_search__popover&amp;quot;}"&gt;&lt;a href="javascript:void(0)" class="a-popover-trigger a-declarative"&gt;&lt;i class="a-icon a-icon-star a-star-4"&gt;&lt;span class="a-icon-alt"&gt;4,2 étoiles sur 5&lt;/span&gt;&lt;/i&gt;&lt;i class="a-icon a-icon-popover"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;    &lt;a class="a-size-small a-link-normal a-text-normal" href="https://www.amazon.fr/MSI-GEFORCE-GTX-1060-3GT/dp/B01KHWOB78/ref=sr_1_18?ie=UTF8&amp;amp;qid=1533908456&amp;amp;sr=8-18&amp;amp;keywords=GTX+1060#customerReviews"&gt;18&lt;/a&gt;&lt;/div&gt;&lt;div class="a-row a-spacing-mini"&gt;&lt;span class="a-size-small a-color-secondary a-text-bold"&gt;Descriptions du produit&lt;/span&gt;&lt;br&gt;&lt;span class="a-size-small a-color-secondary"&gt;... La carte graphique MSI GeForce &lt;em&gt;GTX 1060&lt;/em&gt; 3GT OC met la VR (R&amp;eacute;alit ...&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
  </code></pre>