基于博文仿360小说网站的源码设计实现对小说网站的源码更新升级(动漫小说网)。
网站PC电脑端效果截图:
APP手机端效果截图:
数据库相关表设计:
主要包含小说id,章节id,类型ID,小说名称,章节名称,作者,缩略图,图片地址,是否推荐:1、是2,、否,小说排序,章节排序,更新时间,更新者,创建时间,创建者,状态:1、连载中,2、已完结,简介描述,按字母分类,是否隐藏:1、隐藏,2、显示,最新章节名称,最新章节id、序卷等等。
小说来源采用jsoup自动爬取。
主要html页面源码:
<% var headContent = { include("/template/novel/includes/header.html"){} }; var bodyContent = { include("/template/novel/includes/header_menu.html"){} %>
<% if(!strutil.isEmpty(item.thumbnail)){ %> alt=""> <% } else { %> <% } %> ${item.name}
类型: ${novelweb.getNovelType(item.type_id)}
总字数: ${novelweb.formatWordCount(item.word_count)}
作者: ${item.author}
状态: ${novelweb.showNovelStatus(item.status)}
简介:${javaweb.showHTML2(item.remark!'',500,'......')} ${item.name}由Sky动漫小说网收集整理,是${novelweb.getNovelType(item.type_id)}类的小说,是一部不错的作品哦!
更多推荐 <% for(item in novels){ %>
<% } %>
<% include("/template/novel/includes/footer.html"){} %>
<% }; layout("/pages/template/_layout.html",{head:headContent,body:bodyContent}){} %>
相关java代码:
String novel_img_Path = "***"; File novelUploadPath = new File(novel_img_Path); if (!novelUploadPath.exists()) { novelUploadPath.mkdirs(); } DataLog dataLog = DataLog.dao .findFirst("select max(id) as cnt from data_log"); int log_maxid = (int) (dataLog.get("cnt") == null ? 0 : dataLog .get("cnt")); String logsource = ""; int lognovel_cnt_add = 0; int lognovel_cnt_update = 0; int logchapter_cnt = 0; Document docNovel = null; int id = n_id;// 小说id int cid = c_id;// 章节id String type_id = "";// 类型ID String name = "";// 小说名称 String cname = "";// 章节名称 String author = "";// 作者 String thumbnail = "";// 缩略图 String thumbnail_url = "";// 图片地址 String is_recommend = "2";// 是否推荐:2 否 1 是 String sort = "";// 小说排序 String csort = "";// 章节排序 String update_time = "";// 更新时间 String update_id = "";// 更新者 String create_time = "";// 创建时间 String create_id = "";// 创建者 String status = "2";// 状态//ra dio/2,连载中,1,已完结 String remark = "";// 描述 String zmtype = "";// 按字母分类 String is_show = "1";// 是否隐藏//ra dio/2,隐藏,1,显示 String novel_sql = "";// 小说sql String chapter_sql = "";// 章节sql String txtContent = "";// 章节内容 String update_chapter_name = "";// 最新章节名称 String update_chapter_id = "";// 最新章节id;
sort = nhref.substring(nhref.lastIndexOf("=") + 1, nhref.length()); Elements novel_detail = docNovel .select("div#content table td table"); Element table1 = novel_detail.get(0); name = table1.select("td table td").get(0).text(); type_id = table1.select("tr").get(2).select("td").get(0).text().replaceAll("文库分类:", ""); if (type_id.equals("电击文库")) { type_id = "11"; }else if (type_id.equals("富士见文库")) { type_id = "12"; }else if (type_id.equals("角川文库")) { type_id = "13"; }else if (type_id.equals("MF文库J")) { type_id = "14"; }else if (type_id.equals("Fami通文库")) { type_id = "15"; }else if (type_id.equals("其他文库")) { type_id = "16"; } author = table1.select("tr").get(2).select("td").get(1).text().replaceAll("小说作者:", ""); status = table1.select("tr").get(2).select("td").get(2).text().replaceAll("文章状态:", ""); String word_count = table1.select("tr").get(2).select("td").get(3).text().replaceAll("全文长度:", "").replaceAll("字", ""); if (status.equals("已完成")) { status = "1"; }else { status = "2"; } Element table2 = novel_detail.get(2); thumbnail_url = table2.select("img").get(0).attr("src"); id++; try { URL url = new URL(thumbnail_url); HttpURLConnection conn = (HttpURLConnection) url .openConnection(); conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); conn.setRequestMethod("GET"); conn.setConnectTimeout(5 * 1000); InputStream inStream = conn.getInputStream(); byte[] data = StrUtils.readInputStream(inStream); thumbnail = id + "_no_.jpg"; File imageFile = new File(novel_img_Path + thumbnail); FileOutputStream outStream = new FileOutputStream( imageFile); outStream.write(data); outStream.close(); } catch (FileNotFoundException e) { thumbnail = "default.jpg"; } remark = table2.select("tr td").get(1).text(); remark = remark.substring(remark.indexOf("内容简介:")+5, remark.indexOf("主要角色:")); remark = NovelUtils.FilterStr(remark); zmtype = ChinesePinYinTool .hanziToPinyin(StrUtils.FilterStr(name)) .toUpperCase().charAt(0) + "";
log_maxid++; logsource = "新增小说成功。共新增" + lognovel_cnt_add + "部小说"; logsource = logsource.replaceAll("'", ""); Db.update("insert into data_log values (" + log_maxid + ",'tb_novel','新增数据','" + logsource + "','" + StrUtils.getNow() + "','1');\r\n"); log_maxid++; logsource = "更新小说成功。共更新" + lognovel_cnt_update + "部小说"; logsource = logsource.replaceAll("'", ""); Db.update("insert into data_log values (" + log_maxid + ",'tb_novel','更新数据','" + logsource + "','" + StrUtils.getNow() + "','1');\r\n"); log_maxid++; logsource = "新增章节成功。共新增" + logchapter_cnt + "个章节"; logsource = logsource.replaceAll("'", ""); Db.update("insert into data_log values (" + log_maxid + ",'tb_novel_chapter','新增数据','" + logsource + "','" + StrUtils.getNow() + "','1');\r\n");