前面开发php 的过程中、有一个网站要做一个导航的、需要用到百度热词、百度搜索榜的 top50 。
可以根据for 循环找出50 条
地址可为这几个都可以抓取 是根据simple_html_dom.php
simple_html_dom.php 百度一下 放到相同的目录下
我用的是thinkphp 放在同action中
//http://top.baidu.com/buzz/top10.html
//http://top.baidu.com/buzz?b=1&c=513
//http://top.baidu.com/buzz?b=1&fr=topcategory_c513
$now_url = 'http://top.baidu.com/buzz.php?p=top10';$content = '';if (function_exists ( 'curl_init' )) {$ch = curl_init ( $now_url );curl_setopt ( $ch, curlopt_header, 0 );curl_setopt ( $ch, curlopt_timeout, 30 ); // 设置超时限制防止死循环curl_setopt ( $ch, curlopt_useragent, mozilla/4.0 (compatible; msie 6.0; windows nt 5.0) );// curl_setopt ( $ch, curlopt_useragent,// baiduspider+(+http://www.baidu.com/search/spider.htm) );curl_setopt ( $ch, curlopt_returntransfer, 1 );$content = curl_exec ( $ch );curl_close ( $ch );} elseif (function_exists ( 'file_get_contents' )) {$content = file_get_contents ( $now_url );} else {exit ( '您的服务器同时不支持组件,无法开始采集!' );}include_once ('simple_html_dom.php');// 新建一个dom实例$html = new simple_html_dom ();// 从字符串中加载$html->load ( $content ); // syncad_3$new1 = $html->find ( 'table .keyword .list-title text' ); // 根据table的keyword list-title查出该标签下的数据$keyarray = array ();for($i = 0; $i $item = iconv ( gb2312, utf-8, $new1 [$i] . '' );$keyarray [] = $item;}$this->assign ( 'keyarray', $keyarray );$html->clear ();unset ( $html );
复制代码
top, baidu, php