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
- header("Content-Type:text/html; Charset=UTF-8");
- set_time_limit(0);
- $col_title = ''; //Title
- $col_url = ' '; //URL number
- $user_id = 26; //Start fetching user number
- //MySQL pre-operation
- $mysqli = new mysqli("p:localhost", 'root', '', 'sohutv' );
- if ($mysqli->connect_errno) {
- printf("Connect failed: %sn", $mysqli->connect_error);
- exit();
- }
- $mysqli->set_charset("utf8" );
- $sql = "INSERT INTO album (userid,title,url) VALUES(?,?,?)";
- $stmt = $mysqli->prepare($sql);
- $stmt->bind_param( "sss",$user_id ,$col_title ,$col_url);
-
-
-
- //Loop capture
- while (true) {
- $url = "http://my.tv.sohu.com/user/a/ playlist/ta/list.do?userId=".$user_id;
- $temp_html = file_get_contents($url);
- $temp_json = json_decode($temp_html);
- $column_no = $temp_json->{'data'}- >{'count'};
-
- if ($column_no) {
- //var_dump($temp_json->{'data'});
- $temp_array = $temp_json->{'data'}-> {'list'};
-
- for($i=0; $i<$column_no; $i++)
- {
- $temp_obj = $temp_array[$i];
- //var_dump($temp_obj);
- $col_title = $temp_obj->{'title'};
- $col_url = substr($temp_obj->{'url'}, 25, -6);
-
- $stmt->execute();
- }
- }
- //Sleep for 1 second
- sleep(1);
- $user_id++;
- }
-
- /*
- Access method
- http://my.tv.sohu.com/pl/URL number.shtml
- */
-
- ?> ;
Copy code
|