方法一:用原生file_get_contens()函数
<?php
$results = file_get_contens("http://www.php.net");
echo $page_contents;
//如果要抓取其中的内容,就要看原网站的html源代码,进行字符串正则匹配
$pattern = '/php/';
preg_match($pattern,$page_contents,$result_array);
print_r($result_array);
?>
方法二:借助snoopy,下载地址http://sourceforge.net/projects/snoopy/files/latest/download?source=files
<?php
include "Snoopy.class.php";
$snoopy = new Snoopy;
//抓取整个网页
$snoopy->fetch("http://www.php.net/");
echo $snoopy->results;
//抓取网页的文本,去掉html标签
$snoopy->fetchtext("http://www.php.net/");
print $snoopy->results;
//抓取连接
$snoopy->fetchlinks("http://www.php.net/");
print $snoopy->results;
//更多抓取方法请查看文档!
?>
方法三:借助simple_html_dom,下载地址http://sourceforge.net/projects/simplehtmldom/files/latest/download?source=files
<?php
require('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file('http://www.baidu.com/');
//找到所有标签为a的html,当然也就可以找到其他标签
$a = $html->find('a');
foreach ($a as $key => $value) {
echo $value->href;//输出a标签的href属性
echo "\n";
}
//功能十分强大,更多用法请查看文档!
?>
方法四:其他方法,欢迎补充!