// Include the library
include('simple_html_dom.php');
// Retrieve the DOM from a given URL
$html = file_get_html('http://davidwalsh.name/');
// Find all "A" tags and print their HREFs
foreach($html->find('a') as $e)
echo $e->href . '<br>';
// 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#myId') as $e)
echo $e->innertext . '<br>';
// Find all SPAN tags that have a class of "myClass"
foreach($html->find('span.myClass') as $e)
echo $e->outertext . '<br>';
// Find all TD tags with "align=center"
foreach($html->find('td[align=center]') as $e)
echo $e->innertext . '<br>';
// Extract all text from a given cell
echo $html->find('td[align="center"]', 1)->plaintext.'<br><hr>';
Комментариев нет:
Отправить комментарий