Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Simple HTML DOM to Scrape?
    primarykey
    data
    text
    <p>Simple HTML DOM is basically a php you add to your pages which lets you have simple web scraping. It's good for the most part but I can't figure out the manual as I'm not much of a coder. Are there any sites/guides out there that have any easier help for this? (the one at php.net is a bit too complicated for me at the moment) Is there a better place to ask this kind of question?</p> <p>The site for it is at: <a href="http://simplehtmldom.sourceforge.net/manual.htm" rel="nofollow">http://simplehtmldom.sourceforge.net/manual.htm</a></p> <p>I can scrape stuff that has specific classes like <code>&lt;tr class="group"&gt;</code>, but not for stuff that's in between. For example.. This is what I currently use...</p> <pre><code>$url = 'http://www.test.com'; $html = file_get_html($url); foreach($html-&gt;find('tr[class=group]') as $result) { $first = $result-&gt;find('td[class=category1]',0); $second = $result-&gt;find('td[class=category2]',0); echo $first.$second; } } </code></pre> <p>But here is the kind of code I'm trying to scrape.</p> <pre><code>&lt;table&gt; &lt;tr class="Group"&gt; &lt;td&gt; &lt;dl class="Summary"&gt; &lt;dt&gt;Heading 1&lt;/dt&gt; &lt;dd&gt;&lt;a href="#123" class="ViewProfile"&gt;Cat&lt;/a&gt;&lt;/dd&gt; &lt;dd&gt;&lt;a href="#032" class="ViewProfile"&gt;Bacon&lt;/a&gt;&lt;/dd&gt; &lt;dt&gt;Heading 2&lt;/dt&gt; &lt;dd&gt;&lt;a href="#143" class="ViewProfile"&gt;Narwhal&lt;/a&gt;&lt;/dd&gt; &lt;dd&gt;&lt;a href="#642" class="ViewProfile"&gt;Ice Soap&lt;/a&gt;&lt;/dd&gt; &lt;/dl&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>I'm trying to extract the content of each <code>&lt;dt&gt;</code> and put it to a variable. Then I'm trying to extract the content of each <code>&lt;dd&gt;</code> and put it to a variable, but nothing I tried works. Here's the best I could find, but it gives me back only the first heading repeatedly rather than going to the second.</p> <pre><code>foreach($html-&gt;find('tr[class=Summary]') as $result2) { echo $result2-&gt;find('dt',0)-&gt;innertext; } </code></pre> <p>Thanks to anyone who can help. Sorry if this is not clear or that it's so long. Ideally I'd like to be able to understand these DOM commands more as I'd like to figure this out myself rather than someone here just do it (but I'd appreciate either). </p> <p><strong>TL;DR:</strong> I am trying to understand how to use the commands listed in the manual (url above). The 'manual' isn't easy enough. How do you go about learning this stuff?</p>
    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.
 

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