I need to grab the list of names and descriptions of a website for indexing purposes. How can I do this using PHP? I would think I would have to use DOM correct?
Asked
Active
Viewed 114 times
1 Answers
6
Yes, that is the best way. I would recommend using PHP Simple HTML DOM Parser. You can do spiffy stuff like this:
// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');
// Find all images
foreach($html->find('img') as $element)
echo $element->src . '<br>';
// Find all links
foreach($html->find('a') as $element)
echo $element->href . '<br>';
Whatever you do, do not try parsing HTML with regular expressions.