[英]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? 如何使用PHP执行此操作? I would think I would have to use DOM correct? 我认为我必须正确使用DOM?
Yes, that is the best way. 是的,那是最好的方法。 I would recommend using PHP Simple HTML DOM Parser . 我建议使用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 . 无论您做什么, 都不要尝试使用正则表达式解析HTML 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.