Home > Backend Development > PHP Tutorial > Capture the album names of all users in Sohu Video

Capture the album names of all users in Sohu Video

WBOY
Release: 2016-07-25 08:47:03
Original
1074 people have browsed it
Capture the album names of all users in Sohu Video. If all the records are obtained, video albums with related keywords can be easily retrieved. But because there are too many users, one thread will run for who knows how many years. You can achieve simultaneous capture of multiple channels by setting up multiple tables and ID segments.

You can segment multiple channels at the same time by modifying the start and end of $user_id.

sleep(1) is only for personal testing and can be modified
  1. header("Content-Type:text/html; Charset=UTF-8");
  2. set_time_limit(0);
  3. $col_title = ''; //Title
  4. $col_url = ' '; //URL number
  5. $user_id = 26; //Start fetching user number
  6. //MySQL pre-operation
  7. $mysqli = new mysqli("p:localhost", 'root', '', 'sohutv' );
  8. if ($mysqli->connect_errno) {
  9. printf("Connect failed: %sn", $mysqli->connect_error);
  10. exit();
  11. }
  12. $mysqli->set_charset("utf8" );
  13. $sql = "INSERT INTO album (userid,title,url) VALUES(?,?,?)";
  14. $stmt = $mysqli->prepare($sql);
  15. $stmt->bind_param( "sss",$user_id ,$col_title ,$col_url);
  16. //Loop capture
  17. while (true) {
  18. $url = "http://my.tv.sohu.com/user/a/ playlist/ta/list.do?userId=".$user_id;
  19. $temp_html = file_get_contents($url);
  20. $temp_json = json_decode($temp_html);
  21. $column_no = $temp_json->{'data'}- >{'count'};
  22. if ($column_no) {
  23. //var_dump($temp_json->{'data'});
  24. $temp_array = $temp_json->{'data'}-> {'list'};
  25. for($i=0; $i<$column_no; $i++)
  26. {
  27. $temp_obj = $temp_array[$i];
  28. //var_dump($temp_obj);
  29. $col_title = $temp_obj->{'title'};
  30. $col_url = substr($temp_obj->{'url'}, 25, -6);
  31. $stmt->execute();
  32. }
  33. }
  34. //Sleep for 1 second
  35. sleep(1);
  36. $user_id++;
  37. }
  38. /*
  39. Access method
  40. http://my.tv.sohu.com/pl/URL number.shtml
  41. */
  42. ?> ;
Copy code


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