Note that there are some explanatory texts on larger screens.

plurals
  1. POTaking node values from a site, and re-outputting only selected node tags that can be styled
    primarykey
    data
    text
    <p>I am pulling my hair trying to get this to work with php. </p> <p>The problem: I am just trying to scrape products off a site and have them display as a list of products without anything else that I can style in css. What I'd like to output is <code>&lt;div id='product'&gt;&lt;a href= $link &gt;&lt;img src= $image /&gt;&lt;/a&gt;&lt;br/&gt;&lt;p&gt;$productText&lt;/p&gt;&lt;/div&gt;</code> as a list of products for a site (basically scrape them). This is a project I am trying for fun, here is the code:</p> <pre><code>$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 ); $productName = $xpath-&gt;query( "//div[@id='btfResults']/div/div[4]/div[1]/a/text()" ); $link = $xpath-&gt;query( "//div[@id='btfResults']/div/div[3]/a/@href" ); $image = $xpath-&gt;query( "//div[@id='btfResults']/div/div[3]/a/img/@src" ); foreach ($productName as $n){ $productText = $n-&gt;nodeValue; } foreach ($image as $n){ $imageLink = $n-&gt;nodeValue; } foreach ($link as $n){ $linkLink = $n-&gt;nodeValue; } foreach ($link as $n) { 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> <p>The truth is I have no clue how to get the right results I want. Let me know if this needs further explaining. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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