日期:2012-05-15  浏览次数:20480 次

  1. <?
  2. function get_sub_content($str, $start, $end){      
  3.  if ( $start == '' $end == '' ){             
  4.   return "页面元素已经改变!";       
  5.   }       
  6.   $str = explode($start, $str);       
  7.   $str = explode($end, $str[1]);       
  8.   return $str[0];
  9.   }
  10.  
  11. function my_encoding($data,$to){
  12.  $encode_arr = array('UTF-8','ASCII','GBK','GB2312','BIG5','JIS','eucjp-win','sjis-win','EUC-JP');
  13.  $encoded = mb_detect_encoding($data, $encode_arr);
  14.  $data = mb_convert_encoding($data,$to,$encoded);
  15.  return $data;
  16. }
  17. $doc = file_get_contents("http://video.baidu.com/v?ct=0&word=周杰伦%20site%3Awww%2Etudou%2Ecom&db=0&ty=0&rn=20&pn=0&fbl=1024");
  18. $doc = my_encoding($doc,"utf-8");
  19. $doc =get_sub_content($doc,"<div id=\"result\">","<br clear=");
  20. $str_replace = explode("<div class=x>",$doc);
  21. echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
  22. echo "<data>";
  23. for ($i=1; $i<=count($str_replace)-1; $i++){
  24. echo "<video>";
  25. echo "<name>";
  26. echo "<![CDATA[".get_sub_content($str_replace[$i],"title=\"","\"")."]]>";
  27. echo "</name>";
  28. echo "<pageurl>";
  29. echo "<![CDATA[".get_sub_content($str_replace[$i],"<a href=\"","\" onmousedown=")."]]>";
  30. echo "</pageurl>";
  31. echo "</video>";
  32. }
  33. echo "</data>";
  34. ?>