PHP代理实现用老人机看小说

为了应对当前HTML格式和js脚本对老人机的不友好,我们需要处理一下某些小说网站,让它回到十几年前的样子,剔除大量CSS和JS,精简HTML标签,这样就能够让老人机快速、友好地看小说了。

目前下面的脚本就能实现了,可以为老人机提供简单地浏览和必备的搜索功能,并且支持缓存。

简单说明

_remoteurl_:填写链接
_band_word_:删除关键词
_band_href_:删除URL包含该值的链接
_band_ele_:把某些没有替换掉的元素删除掉,这个设置的存在是由一个正则匹配引起的,一般不要修改。
关于缓存:在源码内搜索$keeptime即可找到相关代码。

快速配置

1. 基本配置

define处修改remoteurl和其他配置,注意看注释,别乱来。

2. 搜索配置

找到if ($_GET['search']) :这一行,下面有

$html = c_get('https://search2.booktxt.net/s.php', 'post', 't=1&keyword='.urlencode(_iconv($_GET['search'], 'GBK')));

这样一行,修改c_get的参数即可。
第一个参数是url,第二个是方式(post/get),第三个是传输过去的请求字符串,可能要用到转码功能,具体看对面页面的编码,用_iconv (脚本自构的函数) 转换。具体写什么需要手动抓取网站信息手动填好。

例子:

# define_remoteurl:  
define('_remoteurl_', 'https://www.biqutxt.com/');
# $_GET['search']后边:
$html = c_get('https://www.biqutxt.com/modules/article/search.php', 'post', 'searchtype=articlename&action=login&searchkey='.urlencode(_iconv($_GET['search'], 'GBK')));

若出现乱码,则可能为转码问题,也可能为原网页的问题,需排查,可以把URL上面的page参数进行urldecode+base64decode即得到源URL。

搬上完整代码:

= $keeptime){
    unlink($cachee);
  }else{
    echo file_get_contents($cachee);
    exit;
  }
}

ob_start();

echo '';
?>



    
    <?php echo 'WT ' . ($_GET['page'] ? base64_decode($_GET['page']) : ''); ?>
    
    



回到主页

搜索小说:
返回:".str_replace(PHP_EOL, '
', $html[1]); $cachee = false; goto foot; } $html = _iconv($html[0]); $html = preg_replace('/<(style|script)[^>]*?>[\s\S]*?<\/\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('/]*?=[^>]*?(?:javascript\:|'._band_href_.')[\s\S]*?<\/a>/i', '', $html); $html = preg_replace('/[\n\r\s]+|( )+/i', ' ', $html); $html = preg_replace('/'._band_word_.'/i', '', $html); $html = preg_replace('/]*?><\/p>|.*?<\/a>|]*?><\/a>/i', '', $html); preg_match_all('/]*?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: ?>
回到主页 [] $val) { $key = _iconv($key, $output); if(is_array($val)) { $data[$key] = _iconv($val, $output); } else { $data[$key] = mb_convert_encoding($data, $output, $encoded); } } return $data; } }

你可能感兴趣的:(php,代理,小说,蛋疼)