Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Fixed and tested:</p> <pre><code>&lt;?php $html = new DOMDocument(); @$html-&gt;loadHtmlFile('http://www.amazon.com/gp/search/ref=sr_nr_p_8_3?rh=n%3A2619533011%2Ck%3Apet+products%2Cn%3A%212619534011%2Cn%3A2975312011%2Cp_72%3A2661618011%2Cp_8%3A2661607011&amp;bbn=2975312011&amp;keywords=pet+products&amp;ie=UTF8&amp;qid=1328429080&amp;rnid=2661603011#/ref=sr_st?bbn=2975312011&amp;keywords=pet+products&amp;qid=1328429127&amp;rh=n%3A2619533011%2Ck%3Apet+products%2Cn%3A!2619534011%2Cn%3A2975312011%2Cp_72%3A2661618011%2Cp_8%3A2661607011'); $xpath = new DOMXPath( $html ); $btfResults = $xpath-&gt;query("//div[@id='btfResults']/div"); // get all item nodes foreach ($btfResults as $node) // iterate through all items { $productText = $linkLink = $imageLink = null; // reset result variables for each loop if ($productName = $xpath-&gt;query("./div[4]/div[1]/a/text()", $node)-&gt;item(0)) // fetch productName node from the item { $productText = $productName-&gt;nodeValue; } if ($link = $xpath-&gt;query("./div[3]/a/@href", $node)-&gt;item(0)) // fetch link node from the item { $linkLink = $link-&gt;nodeValue; } if ($image = $xpath-&gt;query("./div[3]/a/img/@src", $node)-&gt;item(0)) // fetch image node from the item { $imageLink = $image-&gt;nodeValue; } if ($productText &amp;&amp; $linkLink &amp;&amp; $imageLink) // only return a result when all variables are set. { echo '&lt;div id="product"&gt;&lt;a href="'.$linkLink.'"&gt;&lt;img src="'.$imageLink.'"/&gt;&lt;/a&gt;&lt;br/&gt;&lt;p&gt;'.$productText.'&lt;/p&gt;&lt;/div&gt;'; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload