PHP captures the source code of http://top.baidu.com/buzz/top10.html searched by Baidu hot words and can chat privately.

WBOY
Release: 2016-07-25 08:46:37
Original
1724 people have browsed it
In the previous process of developing PHP, there was a website that needed to be navigated, which required the use of Baidu hot words and the TOP50 of Baidu search rankings.

You can find 50 items based on the FOR loop
The address can be grabbed for these based on simple_html_dom.php

simple_html_dom.php Baidu puts it in the same directory
I use THINKPHP and put it in the same 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 ); // Set timeout limit to prevent infinite loop
  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 ( 'Your server does not support components at the same time and cannot start collecting!' );
  17. }
  18. include_once ('simple_html_dom.php');
  19. // Create a new Dom instance
  20. $html = new simple_html_dom ();
  21. // Load from string
  22. $html->load ( $content ); // syncad_3
  23. $new1 = $html->find ( 'table .keyword .list-title text' ); // According to the keyword list of table -title Find out the data under the tag
  24. $keyArray = array ();
  25. for($i = 0; $i < 20; $i ++) {
  26. $item = iconv ( "GB2312", "UTF- 8", $new1 [$i] . '' );
  27. $keyArray [] = $item;
  28. }
  29. $this->assign ( 'keyArray', $keyArray );
  30. $html->clear () ;
  31. unset ( $html );
Copy code
top, baidu, php


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template