以下为引用的内容: <?php //使用Snoopy的抓页功能 include "Snoopy.class.php"; //目标URL $url = $_REQUEST['targeturl']; //将所有传递过来的参数列出来 $par = array(); $GetPost = array_merge($_POST,$_GET); foreach($GetPost As $Key=>$Value){ if($Key!='targeturl'){ $Value = str_replace("%25","%",$Value); array_push($par,($Key . "=" . $Value)); } } //判断目标URL是否带有?(即是否带有参数) $cc = strpos($url,"?") ? "&" : "?"; //重组URL $geturl = !$par ? $url : $url.$cc.implode("&",$par); //抓取重组后的URL页面内容 $snoopy = new Snoopy; $snoopy->fetch($geturl); //替换目标内容中脚本里有可能替换父窗口地址的代码 $org = str_replace("top.location","top.title",$snoopy->results); //尝试转换目标内容编码到UTF-8 $opt = iconv("gbk","utf-8",$org); //判断目标内容编码为GBK或UTF-8 $ec = strlen($opt)?"gbk":"utf-8"; ?> <script type="text/javascript"> //封闭运行,避免与后面内容中脚本混乱 (function(){ var easyUTF8 = function(gbk){if(!gbk){return '';}var utf8 = [];for(var i=0;i<gbk.length;i++){var s_str = gbk.charAt(i);if(!(/^%u/i.test(escape(s_str)))){utf8.push(s_str);continue;}var s_char = gbk.charCodeAt(i);var b_char = s_char.toString(2).split('');var c_char = (b_char.length==15)?[0].concat(b_char):b_char;var a_b =[];a_b[0] = '1110'+c_char.splice(0,4).join('');a_b[1] = '10'+c_char.splice(0,6).join('');a_b[2] = '10'+c_char.splice(0,6).join('');for(var n=0;n<a_b.length;n++){utf8.push('%'+parseInt(a_b[n],2).toString(16).toUpperCase());}}return utf8.join('');}; var getArgs = function(surl){var sarg = surl.split('?'),rv={};rv.filename=sarg[0];if(!sarg[1]){return rv;}var aarg=sarg[1].split('&'),atmp=[];for(var i=0;i<aarg.length;i++){atmp=aarg[i].split('=');rv[atmp[0]]=atmp[1];}return rv;}; var createIPH = function(name,value){if(!name){return;}if(/msie/i.test(navigator.appVersion)){return document.createElement('<input type="hidden" name="'+name+'" value="'+value+'"/>');}else{var dfi = document.createElement('input');dfi.type = 'hidden';dfi.name = name;dfi.value = value;return dfi;}}; //回显目标URL到父窗口文本框 var dtu = top.document.getElementById('targeturl'); if(dtu){dtu.value = '<?php echo $geturl;?>';} //目标URL及domain var sref = '<?php echo $url;?>'; var sdomain = sref.match(/^http:\/\/[^\/]*/i)[0]; //页面加载后执行下面的过程 var process = function(){ //抓取页面中所有链接 var dlink = document.getElementsByTagName('a'),la = dlink.length; //抓取页面中所有表单 var dform = document.getElementsByTagName('form'),lf = dform.length; //遍历所有链接,替换它们的href地址 for(var i=0;i<la;i++){ var src = dlink[i].href.toString().replace(/^http:\/\/www\.w3cgroup\.com(?:\/geturl)?/i,sdomain); var oargs = getArgs(src),ahref = []; //UTF-8编码参数值 for(var d in oargs){ if(!d||d=='filename'||!oargs[d]){continue;} ahref.push(d+'='+encodeURIComponent(easyUTF8(oargs[d]))); } var ghref = ahref.length?oargs.filename+'?'+ahref.join('&'):oargs.filename; //重设链接地址 dlink[i].href = 'http://www.w3cgroup.com/geturl/action_get.php?targeturl='+ghref; } //遍历所有表单,替换它们的action地址 for(i=0;i<lf;i++){ //抓取表单action并处理 var src = dform[i].action.toString().replace(/^http:\/\/www\.w3cgroup\.com(?:\/geturl)?/i,sdomain); if(!(/^http/.test(src))){src = (/^\/.*$/.test(src))?(sdomain+src):(sdomain+'/'+src);} //创建一个隐藏域targeturl,值为上面处理的src地址 var dfi = createIPH('targeturl',src); dform[i].appendChild(dfi); //创建一个隐藏域ie,值为utf-8,纯属为搜索引擎使用 var dfi2 = createIPH('ie','utf-8'); dform[i].appendChild(dfi2); //重设表单提交目标窗口 dform[i].target = 'actioncontent'; //重设表单action地址 dform[i].action = 'http://www.w3cgroup.com/geturl/action_get.php'; //重设表单onsubmit事件,用来UTF8编码字段值 dform[i].onsubmit = function(){ var dlms = this.elements,l = dlms.length-1,pn = '',pt = '',pv = ''; for(var i=0;i<l;i++){ pn = dlms[i].name,pt = dlms[i].type,pv = dlms[i].value; if(!pn||pn=='targeturl'||pn=='ie'){continue;} if(pt=='submit'||pt=='reset'||pt=='button'){ dlms[i].value = encodeURIComponent(pv); }else{ dlms[i].value = encodeURIComponent(easyUTF8(pv)); } } }; } }; //绑定该过程到window.onload if(document.attachEvent){window.attachEvent('onload',process);}else{window.addEventListener('load',process,false);} })(); </script> //脚本放在输出内容前,避免内容中可能出现脚本错误而导致我们要做的事情被废掉 //输出抓到的目标页面内容 <?php echo ($ec=="gbk")?$opt:$org;?> |