如何通过PHP抓取百度热词搜索页面http:top.baidu.combuzztop10.html的源码并私下交流?

更新于
2026-09-26 06:38:53
1阅读来源:SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计327个文字,预计阅读时间需要2分钟。

如何通过PHP抓取百度热词搜索页面http://top.baidu.com/buzz/top10.html的源码并私下交流?

在开发PHP网站过程中,若需制作一个导航,需要用到百度热词和百度搜索排行榜TOP50。可依据FOr循环找出50条,地址可从这几个都可通过simple__dom.php抓取。

如何通过PHP抓取百度热词搜索页面http://top.baidu.com/buzz/top10.html的源码并私下交流?

前面开发PHP的过程中、有一个网站要做一个导航的、需要用到百度热词、百度搜索榜的TOP50。

可以根据FOr循环找出50条
地址可为这几个都可以抓取是根据simple_html_dom.php

simple_html_dom.php百度一下放到相同的目录下
我用的是THINKPHP放在同Action中

//top.baidu.com/buzz/top10.html
//top.baidu.com/buzz?b=1&c=513
//top.baidu.com/buzz?b=1&fr=topcategory_c513

1.[代码][PHP]代码

$now_url = '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+(+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 < 20; $i ++) { $item = iconv ( "GB2312", "UTF-8", $new1 [$i] . '' ); $keyArray [] = $item; } $this->assign ( 'keyArray', $keyArray ); $html->clear (); unset ( $html );

标签:HTTPtopbai

本文共计327个文字,预计阅读时间需要2分钟。

如何通过PHP抓取百度热词搜索页面http://top.baidu.com/buzz/top10.html的源码并私下交流?

在开发PHP网站过程中,若需制作一个导航,需要用到百度热词和百度搜索排行榜TOP50。可依据FOr循环找出50条,地址可从这几个都可通过simple__dom.php抓取。

如何通过PHP抓取百度热词搜索页面http://top.baidu.com/buzz/top10.html的源码并私下交流?

前面开发PHP的过程中、有一个网站要做一个导航的、需要用到百度热词、百度搜索榜的TOP50。

可以根据FOr循环找出50条
地址可为这几个都可以抓取是根据simple_html_dom.php

simple_html_dom.php百度一下放到相同的目录下
我用的是THINKPHP放在同Action中

//top.baidu.com/buzz/top10.html
//top.baidu.com/buzz?b=1&c=513
//top.baidu.com/buzz?b=1&fr=topcategory_c513

1.[代码][PHP]代码

$now_url = '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+(+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 < 20; $i ++) { $item = iconv ( "GB2312", "UTF-8", $new1 [$i] . '' ); $keyArray [] = $item; } $this->assign ( 'keyArray', $keyArray ); $html->clear (); unset ( $html );

标签:HTTPtopbai