php 抓取 百度热词 搜索的 http://top.baidu.com/buzz/top10.html 源码 可私聊。

WBOY
풀어 주다: 2016-07-25 08:46:37
원래의
1660명이 탐색했습니다.
前面开发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
  1. $now_url = 'http://top.baidu.com/buzz.php?p=top10';
  2. $content = '';
  3. if (function_exists ( 'curl_init' )) {
  4. $ch = curl_init ( $now_url );
  5. curl_setopt ( $ch, CURLOPT_HEADER, 0 );
  6. curl_setopt ( $ch, CURLOPT_TIMEOUT, 30 ); // 设置超时限制防止死循环
  7. curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" );
  8. // curl_setopt ( $ch, CURLOPT_USERAGENT,
  9. // "Baiduspider+(+http://www.baidu.com/search/spider.htm)" );
  10. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  11. $content = curl_exec ( $ch );
  12. curl_close ( $ch );
  13. } elseif (function_exists ( 'file_get_contents' )) {
  14. $content = file_get_contents ( $now_url );
  15. } else {
  16. exit ( '您的服务器同时不支持组件,无法开始采集!' );
  17. }
  18. include_once ('simple_html_dom.php');
  19. // 新建一个Dom实例
  20. $html = new simple_html_dom ();
  21. // 从字符串中加载
  22. $html->load ( $content ); // syncad_3
  23. $new1 = $html->find ( 'table .keyword .list-title text' ); // 根据table的keyword list-title查出该标签下的数据
  24. $keyArray = array ();
  25. for($i = 0; $i $item = iconv ( "GB2312", "UTF-8", $new1 [$i] . '' );
  26. $keyArray [] = $item;
  27. }
  28. $this->assign ( 'keyArray', $keyArray );
  29. $html->clear ();
  30. unset ( $html );
复制代码
top, baidu, php


원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!