抓取搜狐視頻中所有使用者的專輯名

來源:互聯網
上載者:User
抓取搜狐視頻中所有使用者的專輯名。如果記錄全部擷取過來以後,可以方便的檢索出相關關鍵詞的視頻專輯。但是由於使用者數目太多,一個線程跑的話不知道要跑多少年。可以通過設定多表、ID分段來實現多通道的同時抓取。

可通過修改$user_id的開始和結束,來分段同時多通道。

sleep(1)僅為個人測試,可以修改
  1. header("Content-Type:text/html; Charset=UTF-8");
  2. set_time_limit(0);
  3. $col_title = '';//標題
  4. $col_url = '';//URL編號
  5. $user_id = 26;//起始抓取使用者編號
  6. //MySQL預操作
  7. $mysqli = new mysqli("p:localhost", 'root', '', 'sohutv');
  8. if ($mysqli->connect_errno) {
  9. printf("Connect failed: %s\n", $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. //迴圈抓取
  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. //休眠1秒
  35. sleep(1);
  36. $user_id++;
  37. }
  38. /*
  39. 訪問方式
  40. http://my.tv.sohu.com/pl/URL編號.shtml
  41. */
  42. ?>
複製代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.