PHP小偷 关于抓取页面不同编码的解决方法!
程序员文章站
2022-04-15 12:36:22
...
其中my_encoding()是转换成你想要编码的方法!本人新手 一点小伎俩 高手见笑!
- function get_sub_content($str, $start, $end){
- if ( $start == '' $end == '' ){
- return "页面元素已经改变!";
- }
- $str = explode($start, $str);
- $str = explode($end, $str[1]);
- return $str[0];
- }
- function my_encoding($data,$to){
- $encode_arr = array('UTF-8','ASCII','GBK','GB2312','BIG5','JIS','eucjp-win','sjis-win','EUC-JP');
- $encoded = mb_detect_encoding($data, $encode_arr);
- $data = mb_convert_encoding($data,$to,$encoded);
- return $data;
- }
- $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");
- $doc = my_encoding($doc,"utf-8");
- $doc =get_sub_content($doc,"","
",$doc);- echo "";
- echo "";
- for ($i=1; $i
- echo "
- echo "
"; - echo "";
- echo "";
- echo "
"; - echo "";
- echo "";
- echo "";
- }
- echo "";
- ?>
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
相关文章
相关视频