0

I have a simple html dom or other scraping question. It could even work to parse the file. I don't know. I am striking out...

I am using Simple HTML Dom to try and get the image from this feed:

http://www.sierraavalanchecenter.org/bottomline-rss.php

// Include the library
include('simple_html_dom.php');

$html = file_get_html('http://www.sierraavalanchecenter.org/bottomline-rss.php'); 

// Retrieve all images and print their SRCs
foreach($html->find('img') as $e)
    echo $e->src . '<br>';

// Find all images, print their text with the "<>" included
foreach($html->find('img') as $e)
    echo $e->outertext . '<br>';

// Find the DIV tag with an id of "myId"
foreach($html->find('div#dangericon') as $e)
    echo $e->innertext . '<br>';

I have tried a few different ways with no luck here. The code above is directly from http://davidwalsh.name/php-notifications.

I am not sure what I am doing wrong. I get some small things like the HR tag now and again, but not the Danger Rose #dangericon->a->img or the text found in .feedEntryContent->table->tbody->tr->td

I would like to put these both into a $variable so I can use them in a different layout.

Thanks for any thoughts.

edit: This got the Danger Rose. There might be something up with the bottom-line.php file...?

<?php
// Include the library
include('simple_html_dom.php');

$html = file_get_html('http://www.sierraavalanchecenter.org/advisory'); 

foreach($html->find('td.views-field-field-danger-rose-php-value img') as $e){
        echo '<img src="http://www.sierraavalanchecenter.org/'. $e->src . '" width="400px" height="180px"/><br>';
}
?>
jasonflaherty
  • 1,924
  • 7
  • 40
  • 82

1 Answers1

1

The file you are trying to parse here is a xml file.

I'd recommend you parsing it using simplexml_load_file (http://nz.php.net/manual/en/function.simplexml-load-file.php)

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

$xml = simplexml_load_file('http://www.sierraavalanchecenter.org/bottomline-rss.php');

$description = (string)$xml->channel->item->description;

$html = new simple_html_dom();
$html->load($description);

foreach($html->find('img') as $image) {
echo $image->src . '<br/>';
} 
?>
Tim
  • 320
  • 1
  • 8