views:

184

answers:

1

I'm trying to use simple html DOM to extract everything inside a tag with the class "sitepoint". Here is my code that doesn't work:

<?php
include_once('simple_html_dom.php');

$html = file_get_html('examplewebsite');
$ret = $html->find('.sitepoint');
echo $ret;

?>

Below is an example of one of the sitepoint tags (there are ten or so) with the information inside which I want.

<dl class="sitepoint">
<dd class="thumbnail">
<a href="blabla" ></a><a href="/toolbar/sidepanel.php?url=random.html" >Get This      Now</a>   </dd><dt class="notext"><a href="/to/" >Title</a></dt><dd class="starts">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td class="textUncolor"> CUT OUT SOME IMAGES AND       ADDRESSES HERE
                            </td></tr>
</table>
</dd>

Can anyone help me get it working?

A: 

You need to access the outertext attribute.

 $html->find('.sitepoint',0)->outertext;

Check the docs for more info. Look under "magic attributes"

EDIT

When selecting classes, you need to specify which one in the document you use. I've changed the above example to reflect this. This is tested and works. (notice the 0 as the second parameter to find)

Byron Whitlock
Hello, I changed the line to $html->find('.sitepoint')->outertext;and it didn't work.
David Willis
does the html close the <dl> tag?
Byron Whitlock
Ah I must have left the </dl> tag out, it's closed in the html.Btw there are several <dl></dl> tags in the document.Would appreciate if someone could tell me where I am going wrong here.
David Willis
That works, thanks man!
David Willis