首页 > CMS教程 > 正文

PHP代理实现用老人机看小说
2020-02-27 21:03:00   来源:   评论:0 点击:

为了应对当前HTML格式和js脚本对老人机的不友好,我们需要处理一下某些小说网站,让它回到十几年前的样子,剔除大量CSS和JS,精简HTML标签,这样就能够让老人机快速、友好地看小说了。 目前下面的脚本就能实现了,可以为老人机提供简单地浏览和必备的搜索
));

else:

$html = c_get(_remoteurl_);

endif;

if (!preg_match(/200 OK/i, $html[1])) {

echo 服务器可能出现了点问题噢(⊙o⊙)?;

echo "<br />返回:".str_replace(PHP_EOL, <br />, $html[1]);

$cachee = false;

goto foot;

}

$html = _iconv($html[0]);

$html = preg_replace(/<(style|)[^>]*?>[sS]*?</1>/i, , $html);

$html = preg_replace(/<(?:._band_ele_.)[^>]*?>/i, , $html);

$html = preg_replace(/<(?!a|/a|p|/p|br|li|/li|table|/table|td|/td|tr|/tr)(?:[^>]*?)>/i, , $html);

$html = preg_replace(/(id|class|title|style|target|alt|onclick)=("|).*?2/i, , $html);

$html = preg_replace(/<a[^>]*?=[^>]*?(?:java:|._band_href_.)[sS]*?</a>/i, , $html);

$html = preg_replace(/[nrs]+|( )+/i, , $html);

$html = preg_replace(/._band_word_./i, , $html);

$html = preg_replace(/<p[^>]*?></p>|<a >.*?</a>|<a[^>]*?></a>/i, , $html);

preg_match_all(/<a[^>]*?href=("|)([^>]*?)1/i, $html, $links);

$rep = [];

$rem = [];

foreach ($links[2] as $key => $value) {

if (!(strlen($links[2][$key]) > 5)) continue;

$qt = $links[1][$key];

$rep[] = $qt . $links[2][$key] . $qt;

$rem[] = $qt . "?page=".urlencode(base64_encode(rel2abs($value))) . $qt;

}

if (count($links) > 1)

$html = str_replace($rep, $rem, $html);

echo $html;

foot:

?>

<br />

<a href="?">回到主页</a>

<small>[<?php echo date("y-m-d H:i:s"); ?>]</small>

</body>

</html><?php

$html = ob_get_clean;

echo $html;

if ($cachee)

file_put_contents($cachee, $html);

function c_get($url, $method = get, $data = , $referer = _remoteurl_, $timeout = 10, $useck = false, $saveck = false, $ckfile = "ck.txt") {

$headerinfo = array(

"User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

);

$ch = curl_init;

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headerinfo);

curl_setopt($ch, CURLOPT_TIMEOUT_MS, $timeout * 1000);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_REFERER, $referer);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_HEADER, true);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

if ($saveck == true) {

curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);

}

if (file_exists($ckfile) && $useck == true) {

curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);

}

if ($method == "post") {

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

}

$content = curl_exec($ch);

if (curl_errno($ch)) {

return Curl error: . curl_error($ch);

}

if ($content == false) {

return "Get content false!";

}

$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);

$header = substr($content, 0, $headerSize);

$body = substr($content, $headerSize);

if (in_array(curl_getinfo($ch, CURLINFO_HTTP_CODE), [301,302])) {

preg_match("@location: (.*?)[nr;]@i", $header, $tmpgo);

curl_close($ch);

return c_get($tmpgo[1]);

}

curl_close($ch);

$content = array(

$body,

$header

);

return $content;

}

function rel2abs($n){

if ($_GET

相关热词搜索:

上一篇:近 50 种花式 “Hello, World”
下一篇:玩转容器技术

分享到: 收藏