简体   繁体   中英

How can I grab information using PHP?

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM