可否帮忙写一个单页页的PHP采集程序,并附上实例 比方说,我要采集这个页面:http://news.163.com/12/0613/20/83TJ7PA700014JB6.html要求:采集标题采集正文谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 首先去http://simplehtmldom.sourceforge.net/index.htm(点击Download latest version form Sourceforge.)下载一个simple_html_dom.php,傻瓜式的正则,另官网上有详细教程,很容易看懂。header("Content-type: text/html; charset=gb2312");require dirname(__FILE__) . '/simple_html_dom.php';$ch = curl_init();curl_setopt($ch, CURLOPT_URL, 'http://news.163.com/12/0613/20/83TJ7PA700014JB6.html');curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');$htmls = curl_exec($ch);curl_close($ch);$html = str_get_html($htmls);foreach($html->find('#h1title') as $title){ echo strip_tags($title).'<br />';//标题}foreach($html->find('#endText') as $content){ echo strip_tags($content);//正文}注:curl模拟Mozilla浏览器抓取,比file_get_contents()解析速度更快。strip_tags() 用以去除那个邪恶的iframe广告,反正你需要的是“采集标题”和“采集正文”冗余的html标签对你无用。 PHP获取QQ邮箱好友列表的方法: 用抓取页面就可以,标题的话就是title标签之间的,正文是body之间的,用正则去掉一些不需要的内容 这样的数据结构怎么写程序 数据无法写入数据库 PHP服务器如何配置openssl 循环显示数据的问题 显示多个表中的记录 安装错误!请在安装目录的setup目录中执行安装 页面刷新就不能显示的问题 操蛋,修复BUG,请问怎么修复这个bug 发手机短信能实现吗? 高分求助php,oracle连接配置问题 关于微信 PHP采集高手进!这个网站是怎么防采集的? 在PHP下操作网络驱动器的方法
header("Content-type: text/html; charset=gb2312");
require dirname(__FILE__) . '/simple_html_dom.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://news.163.com/12/0613/20/83TJ7PA700014JB6.html');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
$htmls = curl_exec($ch);
curl_close($ch);
$html = str_get_html($htmls);
foreach($html->find('#h1title') as $title){
echo strip_tags($title).'<br />';//标题
}
foreach($html->find('#endText') as $content){
echo strip_tags($content);//正文
}注:curl模拟Mozilla浏览器抓取,比file_get_contents()解析速度更快。strip_tags() 用以去除那个邪恶的iframe广告,反正你需要的是“采集标题”和“采集正文”冗余的html标签对你无用。