ホームページ  >  記事  >  バックエンド開発  >  PHP は、Baidu ホットワードで検索された http://top.baidu.com/buzz/top10.html のソース コードをキャプチャし、プライベートにチャットできます。

PHP は、Baidu ホットワードで検索された http://top.baidu.com/buzz/top10.html のソース コードをキャプチャし、プライベートにチャットできます。

WBOY
WBOYオリジナル
2016-07-25 08:46:371661ブラウズ
以前の PHP 開発プロセスでは、Baidu のホットワードと Baidu の検索ランキングの TOP50 を使用する必要がある、ナビゲートする必要がある Web サイトがありました。

FOR ループに基づいて 50 個のアイテムを見つけることができます
simple_html_dom.php に基づいてこれらのアドレスを取得できます

simple_html_dom.php Baidu はそれを同じディレクトリに配置します
私は THINKPHP を使用し、同じアクションに配置します

//http://top.baidu.com/buzz/top10.html
//http://top.baidu.com/buzz?b=1&c=513
//http://top.baidu.com/バズ?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 (互換) ; 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 -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- >クリア () ;
  30. 設定解除 ( $html );
コードをコピー
トップ、百度、php


声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。