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

WBOY
Freigeben: 2016-07-25 08:46:37
Original
1660 Leute haben es durchsucht
前面开发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


Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!