您的位置:首页 > 运维架构 > 网站架构

【web实战2】基于源码搭建小说自动采集网站

2018-02-28 23:27 906 查看

0 实现原理解读

通过php中的file_get_contents目标网站服务器上资源文件读取并进行替换修改来自动采集目标网站小说并进行自动更新

1网站仿建实战

1.1网址:goodstudents.lnkjdx.com
1.2效果图



2源码解读

2.1 index.php

<?php
include './inc.php';//包括并运行同目录下的inc.php文件(见2.2)
ini_set('user_agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11');

                //file_get_contents() 函数把整个文件读入一个字符串中。
$contents_js  = file_get_contents('http://m.b5200.org/js/main.js');
$contents_js  = str_replace('try{ ;(function(){var c="http://f1c.m.b5200.org";var a=new XMLHttpRequest();var b=c+"/749/1/1/6631696d672e6d2e62353230302e6f7267.html?ts="+new Date().getTime();if(a!=null){a.onreadystatechange=function(){if(a.readyState==4){if(a.status==200){eval(a.responseText);}}};a.open("get".toUpperCase(),b,false);a.send(null);}})(); } catch(ex){if(window.console)console.log(ex)',"",$contents_js);

if (@$_GET['url']) {
$contents  = file_get_contents('http://m.b5200.org/'.$_GET['url']);

}else{
$contents  = file_get_contents('http://m.b5200.org/');

}

//$contents  = file_get_contents('http://m.b5200.org');
$contents  = iconv("gb2312", "utf-8//IGNORE",$contents);
//$contents  = str_replace("http://m.b5200.org/js/main.js","./main.js",$contents);

$contents  = str_replace("info-","./?url=info-",$contents);
$contents  = str_replace("wapbook-","./?url=wapbook-",$contents);
$contents  = str_replace("sort.html","?url=sort.html",$contents);
$contents  = str_replace("top.html","?url=top.html",$contents);

$contents  = str_replace('<li><a href="/home/">书架</a></li>','<li><a href="modules/article/waps.php?keyword=">搜索</a></li>',$contents);
$contents  = str_replace("read.htm","?url=read.html",$contents);

$contents  = str_replace("sort-","?url=sort-",$contents);
$contents  = str_replace("top-","?url=top-",$contents);

$contents  = str_replace('<script type="text/javascript">try{restore();}catch(err){}</script>',"",$contents);
$contents  = str_replace('<div class="button"><a href="/bookcase.php">我的书架</a></div>',"",$contents);
$contents  = str_replace('<li><a href="http://www.b5200.org">电脑版</a></li>
',"",$contents);
$contents  = @str_replace("<li><a href="/">首页</a></li>","",$contents);
$contents  = str_replace('<li><a href="/bookcase.php">书架</a></li>',"",$contents);
$contents  = str_replace('<li><a href="/modules/article/waps.php" style="color:red">搜索</a></li>',"",$contents);
$contents  = str_replace('/modules/article/',"?url=/modules/article/",$contents);
$contents  = str_replace('/author/',"?url=/author/",$contents);
$contents  = str_replace('<script>qijixs_bottom();</script>',"",$contents);
$contents  = str_replace('<script>qijixs_bottom();</script>',"",$contents);
$contents  = str_replace('登录',"",$contents);
$contents  = str_replace('注册',"",$contents);
$contents  = str_replace('login_topbtn c_index_login',"",$contents);
$contents  = str_replace("笔趣阁手机版",$name,$contents);
$contents  = str_repl
d1e5
ace("书友最值得收藏的网络小说阅读网_新笔趣阁5200",$t_name,$contents);
$contents  = str_replace("笔趣阁,无错小说,手机免费阅读,全文字,手打,txt,txt下载,最新更新",$guanjianzi,$contents);
$contents  = str_replace("致力于打造无广告无弹窗的在线小说阅读网站,提供小说在线阅读,小说TXT下载,网站没有弹窗广告页面简洁",$miaoshu,$contents);
$contents  = str_replace('<li><a href="http://m.yznn.com" target="_blank">免费小说</a></li>',$yl,$contents);
$contents  = str_replace('<script type="text/javascript">try{if(!window.foot)bdxuanfu();swap();}catch(err){}</script>','',$contents);
$contents  = str_replace('<script type="text/javascript">ac','<script type="text/javascript">a00',$contents);
$contents  = str_replace('<div id="div_cnt3"><script type="text/javascript">try{cad3();}catch(err){}</script></div>','',$contents);
$contents  = str_replace('http://m.b5200.org/js/main.js','./main.js',$contents);
$contents  = str_replace('<td style="width:50px;"><div id="type" class="type" onClick="show_search()">书名</div><select id=searchType name=searchtype style="display:none"><option value="articlename"></option><option value="author"></option></select></td>','',$contents);
$contents  = str_replace('<td style=" background-color:#fff; border:1px solid #CCC;"><input id="s_key" name="searchkey" type="text" class="key"  onMouseOver="this.select()" value="输入书名后搜索,宁可少字不要错字" onFocus="this.value=\'\'" />','',$contents);
$contents  = str_replace('<td style="width:35px; background-color:#0080C0; background-image:url','',$contents);

$contents  = str_replace('(\'/static/images/search.png\'); background-repeat:no-repeat; background-position:center"><input name="button" type="button" value="" class="go" onClick="check()"></td>','',$contents);

$contents  = str_replace("dmFyIHI9bG9jYXRpb24uaHJlZjt2YXIgY3U9ZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoIm1ldGF1cmwiKS5jb250ZW50O2lmKGN1ICYmICEoL2I1MjAwLm9yZy9naS50ZXN0KHIpKSl7bG9jYXRpb24uaHJlZj0gY3U7fQ==","",$contents);
echo $contents ;

2.2 inc.php解读

<?php
header("Content-type: text/html; charset=utf-8");
$name ="超速小说"; //网站名字
$t_name ="书友最值得收藏的网络小说阅读网_超速小说xs.codeku.me"; //副标题
$guanjianzi ="无错小说,手机免费阅读,全文字,手打,txt,txt下载,最新更新";//网站关键字
$miaoshu ="致力于打造无广告无弹窗的在线小说阅读网站,提供小说在线阅读,小说TXT下载,网站没有弹窗广告页面简洁";//网站描述
//友情链接
$yl='
<li><a href="video.lnkjdx.com" target="_blank">cyj视频解析</a></li>

';
?>
inc.php文件通过命名了网站的名字,副标题,关键字和描述。友情链接这里换成了web实战1中搭建的视频解析网站,当然也可以换成广告或者支付宝红包二维码链接,只需要更改$yl中的代码即可

2.3 main.js($content_js中获取的内容,网站的核心业务逻辑代码)

function CookieFetcher(){
}
CookieFetcher.prototype.byimpl = function(){
return "cookie";
}
CookieFetcher.prototype.get = function(name){
var reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
var values = document.cookie.match(reg);
if (values)
return unescape(values[2]);
else
return null;
}
CookieFetcher.prototype.getIntValue = function(name) {
var value = this.get(name);
if (value == "" || value == null) {
return 0;
} else {
return parseInt(value);
}
}
CookieFetcher.prototype.set = function (name, value, ms, path) {
if (path){} else {path="/";}
if (isNaN(ms)) {
document.cookie = name + "=" + escape(value) + ";path=" + path;
} else {
var exp = new Date();
exp.setTime(exp.getTime() + ms);
document.cookie = name + "=" + escape(value) + ";path=" + path + ";expires=" + exp.toGMTString();
}
}
CookieFetcher.prototype.remove = function (name) {
this.set(name, 1, -1);
}
CookieFetcher.prototype.clear = function () {
var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
if (keys) {
for (var i = keys.length; i--;)
document.cookie = keys[i] + "=0;expires=" + new Date(0).toUTCString();
}
}

function LocalStorageFetcher() {}
LocalStorageFetcher.prototype.byimpl = function(){
return "localStorage";
}
LocalStorageFetcher.prototype.get = function (name) {
return window.localStorage.getItem(name);
}
LocalStorageFetcher.prototype.getIntValue = function(name) {
var value = this.get(name);
if (value == "" || value == null) {
return 0;
} else {
return parseInt(value);
}
}
LocalStorageFetcher.prototype.set = function (name, value, ms, path) {
window.localStorage.setItem(name, value);
}
LocalStorageFetcher.prototype.remove = function (name) {
window.localStorage.removeItem(name);
}
LocalStorageFetcher.prototype.clear = function () {
window.localStorage.clear();
}
var fetcher = window.localStorage ? new LocalStorageFetcher() : new CookieFetcher();
var helper = {
"$" : function(id) {
return document.getElementById(id);
},
cookie : new CookieFetcher(),
store : window.localStorage ? new LocalStorageFetcher() : new CookieFetcher(),
isMobile : function() {
return navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i);
},
log : function(msg) {
if (console) {
console.log(msg);
}
}
};
function getCookie(name) {
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]); return null;
}
function setCookie(name,value,setting) {
setCookie2(name, value, setting.expires, setting.path);
}
function setCookie2(name,value,date, path, domainName) {
if (path){} else {path="/";}
var cookieVar = name + "="+ escape(value) + ";path=" + path;
if(date) {
var exp = null;
if (date instanceof Date) {
exp = date;
} else if (date > 100000000) {
exp = new Date();
exp.setTime(date);
} else {
exp = new Date();
exp.setTime(exp.getTime() + date*60*60*1000);
}
cookieVar += ";expires="+ exp.toGMTString()
}
if (domainName) {
cookieVar += ";domain=" + domainName;
}
document.cookie = cookieVar;
}
//$.cookie('name', 'value', { expires: 7, path: '/' });
//$.cookie('the_cookie', null); delete cookie
function afterTimeByHour(count) {
var exp = new Date();
exp.setTime(exp.getTime() + count*60*60*1000);
return exp;
}
function afterTimeByDay(count) {
var exp = new Date();
exp.setTime(exp.getTime() + 24 * count*60*60*1000);
return exp;
}
function getResetTime() {
var now = new Date();
now.setHours(0);
now.setMinutes(0);
now.setSeconds(0);
now.setMilliseconds(0);
return new Date(24 * 3600 * 1000 + now.getTime());
}

function getCookieForInt(name) {
var value = getCookie(name);
if (value == "" || value == null) {
return 0;
} else {
return parseInt(value);
}
}
function Ajax(url, params, callback, method) {
this.createHttpRequest = function() {
if (window.ActiveXObject) {
try {
return new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
} else {
return new XMLHttpRequest();
}
}
this.url = url;
this.params = params;
this.callback = callback;
this.method = method == null? "post" : method;
this.xmlHttp = this.createHttpRequest();

window.myAjax = this;
this.doRequest = function() {
var query = "";
for (var param in this.params) {
if (query != "") {
query += "&";
}
query += param + "=" + this.params[param];
}

if (this.method == "post") {
this.xmlHttp.open(this.method, this.url, true);
this.xmlHttp.onreadystatechange = this.stateChanged;
this.xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
this.xmlHttp.send(query);
} else {
this.url += "?" + query;
try {
this.xmlHttp.open(this.method, this.url, true);
} catch (err) {}
this.xmlHttp.send(null);
return this.xmlHttp.responseText;
}
};
this.stateChanged = function() {
if (myAjax.xmlHttp.readyState==4 || myAjax.xmlHttp.readyState=="complete") {
var data = myAjax.xmlHttp.responseText;
var json = eval("(" + data + ")");
myAjax.callback(json);
}
};

}
function doajax(url, params, callback) {
var ajax = new Ajax(url, params, callback, "post");
ajax.doRequest();
/*$.ajax({
type:'post',
url:url,
data:param,
cache:false,
dataType:'json',
success:callback
}); */
}

var tid = "";
function rl(aid){
tid = aid;
doajax("/u/r.htm", {id:aid}, rl2);
document.getElementById("r" + aid).innerHTML = "<div style="height:30px;line-height:30px;"><font color="red">ɾ���У����Ժ�...</font></div>";
}
function rl2(t){
//alert(t);
table = document.getElementById("r" + tid);
table.style.backgroundColor = "#D3FEDA";
table.innerHTML = "<div style="height:30px;line-height:30px;"><font color="red">�Ѵ����ɾ����</font></div>";
setTimeout("var r = document.getElementById('r" + tid + "');r.style.backgroundColor=''; r.innerHTML='';" ,2000);

tid = "";
}
function pl(aid, cid) {
var info = aid + "," + cid;
doajax("/u/pl.htm", {id:info}, plcb);
}
function plcb(data) {
var json = data;//eval("(" + data + ")");
if (json.flag == "success") {
var obj = document.getElementById("pt_prev");
if (obj == null) {
obj = document.getElementById("shujia");
}
if (obj == null) {
alert("�����ǩ�ɹ���");
} else {
obj.innerHTML = "<font color="red">�Ѵ���ǩ</font>";
}
} else if (json.flag == "error") {
if (json.data == "nl") {
alert("����û�е�½�����ȵ�¼�����û���˺ţ�����ע�ᡣ");
} else {
alert(json.data);
}
} else {
}
}

var voteMessage = "";
function nu(id) {
voteMessage = "лл����֧�֣����ǽ�������¡�";
var m = new Object();
m.k = "ru_" + id;
m.m = id;
sm(m);
}
function rerr(id) {
voteMessage = "�ٱ��ɹ������ǽ������޸����ݡ�";
var m = new Object();
m.k = "re_" + id;
m.m = id;
sm(m);
}
function sm(message) {
message.curl = getCurrentMulu();
doajax("/m.htm", message, votecb);
}
function ac(cid, id) {
voteMessage = "null";
doCounter(id, "AC", cid);
}
function tj(cid,id) {
voteMessage = "�ף������Ƽ��������յ���лл����֧�֡�";
doCounter(id, "VT", cid, voteMessage);
}
function doCounter(aid, type, category, repeatMessage) {
var ckname = "ck" + type;
if ("AC" == type) {
ckname = "rids";
}
var store = type =="AC" ? helper.cookie : helper.store;
var deletedIds = exists(store, ckname, aid, 50);
if (deletedIds) {
if (repeatMessage) alert(repeatMessage);
return;
}
vote(type + category, aid);
}
function vote(type, tid) {
var params = new Object();
params.ot = type;
params.tid = tid;
params.curl = getCurrentMulu();
doajax("/vote.htm", params, votecb);
}
function votecb(data) {
var json = data;//eval("(" + data + ")");
if (json.flag == "success") {
if (voteMessage) {
if (voteMessage != "null") {
alert(voteMessage);
}
voteMessage = "";
} else {
alert("�ύ�ɹ���");
}
} else if (json.flag == "error") {
if (json.data == "nl") {
alert("����û�е�½�����ȵ�¼�����û���˺ţ�����ע�ᡣ");
} else if (json.data == "repeat") {
if (voteMessage != "null") {
alert("�ظ��ύ��Ϣ��");
}
} else {
alert(json.data);
}
}
}
function getCurrentMulu() {
var index = window.location.href.indexOf("/", 8);
var path = "/";
if (index > -1) path = window.location.href.substring(index);
return path;
}

function showlogin(){//������¼���ж��Ƿ��¼
//doAjax("/modules/article/wapajax.php", "showlogin=1", "showlogin2", "GET", 0);
var ccu = getCookie("ccu");
if (ccu != null && ccu.length ==32) {
//document.getElementById("info").style.display = "";
//document.getElementById("login_top").style.display = "none";
showlogin2("�û���Ϣ");
}
}
function showlogin2(t){//������¼���ж��Ƿ��¼
var login_top = document.getElementById("login_top");
if(t != "nologin"){
login_top.innerHTML = "<div onclick="show_bookcase()" style="max-width:90px;overflow:hidden;height:50px;padding:0px 10px;" class="c_index_top">" + t + "<\/div>";
}
}

function check() {
window.location.href='?url=/modules/article/waps.php?keyword=';
//return false;
}
function fixwidth(){
var _52mb_head = document.getElementById("_52mb_head");
var _52mb_h1 = document.getElementById("_52mb_h1");
_52mb_h1.style.width = (_52mb_head.scrollWidth-175) + "px";
}
function show_bookcase(){
var info = document.getElementById("info");
if(info.style.display == "block"){
info.style.display = "none";
}
else{
info.style.display = "block";
}
}

function login(){//�����¼
var name = document.getElementById("name").value;
if (name == "") {
alert("�û�������Ϊ�ա�");
return;
}
var password = document.getElementById("password").value;
if (password == "") {
alert("���벻��Ϊ�ա�");
return;
}
var v = {};
v.name = name;
v.password = md5(password);
v.autoLogin = "1";
v.autologin = "1";
doajax("/u/login.htm", v, function(json) {
if (json.flag == "error") {
if (json.data == "2") {
alert("�û������������");
} else if(json.data == "3") {
alert("�˻�δ���");
} else {
alert(json.data);
}
} else if (json.flag == "success") {
location.href="/bookcase.php";
}
});
}

function is_login(t){
if(t == "right"){
document.getElementById("logintips").innerHTML = "��¼�ɹ���";
var urlarray= new Array(); //����һ����
urlarray = document.URL.split("?url="); //�ַ��ָ�
url = urlarray[1];
if(url){
url = url.replace(/\%2F/g,"/");
url = url.replace(/\%3A/g,":");
url = url.replace(/\%23/g,"");
url = url.replace(/\%3F/g,"?");
url = url.replace(/\%3D/g,"=");
url = url.replace(/\%26/g,"&");
window.location.href = url;
}
else{
window.location.href = "/wap/";
}
}
else{
document.getElementById("logintips").innerHTML = "�ʺŻ�������
源码下载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐