小说解析
By
admin
at 2018-09-15 • 0人收藏 • 1708人看过
import console; import web.rest.client; import inet.url; import string.html; //获取百度转码后的小说站点 var get_site = function(word){ var http = web.rest.client(); var bdxs = http.api("https://m.baidu.com/s?word={word}",,{ url =`\<div class="wa-nvl-trans-btn-wrap c-span3".*?>.*?\<a href="(.*?)" data-visited="off" voice-tag="免费阅读"` }) var dzs_url = string.html.toText(bdxs[word].get().url); //百度转码后的小说站 if(dzs_url){ jx = http.api(dzs_url,,{ url = `replace\("(.*?)"`; }) dzs_url = jx.get().url; if(dzs_url="http://m.baidu.com/error.jsp"){ console.log("解析错误") } } else { console.log("未找到有效资源") return ; } return dzs_url; } ; //获取最新章节信息 var get_newChapter = function(dzs_url){ var http = web.rest.client(); var info = http.api(dzs_url,,{ url = `\<span class="global-icon-bg-orange"\>最新\</span\>.*?\<a class="invoke" data-function="getChapterContent" data-href="(.*?)".*?\>.*\</a\>`; title = `\<span class="global-icon-bg-orange"\>最新\</span\>.*?\<a class="invoke" data-function="getChapterContent" data-href=".*?".*?\>(.*?)\</a\>`; cid = `\<span class="global-icon-bg-orange"\>最新\</span\>.*?\<a class="invoke" data-function="getChapterContent" .*?data-cid="(.*?)".*?\>.*?\</a\>`; }) return info.get(); } ; //获取前50章节信息 var get_Chapter = function(dzs_url){ import string.html; import web.json; var http = web.rest.client(); var info = http.api(dzs_url); var pattern = `onPageletArrive\((.*?)\);\</script\>` var res = string.matches(info.get(),pattern) var html = ""; for(k,v in res){ var id = web.json.parse(v[1]).id if(id="chapterInfo"){ html = string.html(web.json.parse(v[1]).html); } else { } } var ele = html.queryEles({ tagName = "ul"; id = "J-ascChapterList\d+"; }); var list = {}; for(k,v in ele){ for(k,v in v.li){ var tab = {}; tab.title = v["data-title"]; tab.href = v["data-href"]; tab.cid = v["data-cid"] table.push(list,tab) } } //console.dump(ele[1].li[1]["data-title"]) //console.dump(list) return list; } ; var get_txt = function(dzs_url){ if(dzs_url=null){ return ; } import inet.url; var url_info = inet.url.split(dzs_url); var tab = inet.url.splitParameters(url_info.extraInfo); //添加cid,url参数 tab.cid = get_Chapter(dzs_url)[1].cid; tab.url = get_Chapter(dzs_url)[1].url; while(tab.cid!=null){ var http = web.rest.client(); url_info.extraInfo = "?"+inet.url.stringifyParameters(tab) var info = http.api(tostring(url_info)); var pattern = `onPageletArrive\((.*?)\);\</script\>` var res = string.matches(info.get(),pattern) var html = ""; for(k,v in res){ var id = web.json.parse(v[1]).id if(id="chapterContent"){ html = string.html(web.json.parse(v[1]).html); } else { } } var ele = html.queryEles({ tagName = "div"; }) console.log(html[1].h1[1].innerText())//标题 console.setTitle(html[1].h1[1].innerText()) console.log("=============") console.dump(string.html.toText(html[1].div[1].innerXml()))//正文 tab.cid = console.askYesNo("加载下一章,按Y键继续,按N键取消")?html[1].div[3]["data-cid"]:null console.clearScreen () tab.url = html[1].div[3]["data-href"]; } /* console.log("上一章cid:"++html[1].div[2]["data-cid"],"上一章href:"++html[1].div[2]["data-href"])//上一章信息 console.log("=============") console.dump(html[1].div[3])//下一章信息,cid为空则为最后一章 */ } ; //测试 //var word = "葫芦娃"; //制造一个错误 //var word = "夜天子"; //正确搜索词 //var word = "斗罗大陆"; //正确搜索词 var word = "妖神记"; //正确搜索词 var dzs_url = get_site(word)//小说站点 get_txt(dzs_url) //搜索一下 /* console.log(dzs_url) console.askYesNo("获取最新章节信息,按Y键继续,按N键取消") console.dump(get_newChapter(dzs_url)) console.askYesNo("是否获取前50章列表按Y键继续,按N键取消") console.dump(get_Chapter(dzs_url)) */ //console.dump(get_newChapter(dzs_url)) console.pause(true);
感谢: aar培训群的 撒旦微笑 提供
登录后方可回帖