(转)lofter 文章图片采集
By
admin
at 2018-09-14 • 1人收藏 • 1413人看过
import console; import web.rest.client; import fsys; import inet.url; var path = fsys.getSpecial(0 /*_CSIDL_DESKTOP*/)++"/img"//保存目录 //获取文章图片地址url为文章地址,返回img地址数组 var img_get = function (url) { /* 配置不同主题的抓取参数; var config = { ["63001"] = "img"; ["132003"] = "pic"; ["133001"] = "pic"; }; */ var http = web.rest.client(); var img = http.api(url); import string.html; var html = string.html(img.get()); //var id = html.queryEles(name = "themename").content; //获取主题ID var ele = html.queryEles( tagName = "div"; ) var data = {}; /* //按主题配置抓取 for(k,v in ele){ if(config[id]){ if(v.class=config[id]){ table.push(data,v.a[1].img[1].src) } } else { console.log("缺少配置文件") } } */ for (k, v in ele) { if (v.class = "pic") { table.push(data, v.a ? v.a[1].img[1].src : v[1].a[1].img[1].src)//如果个别主题样式差异,可以单独设置config } } return data; }; //默认从当前页采集到最后一页 var lofter_list = function (url) { //var lists = {}; while (url) { var http = web.rest.client(); var img = http.api(url,, { next = `\<a class="next" href="(.*?)" id="__next_permalink__"\>下一篇.*?\</a\>`; title=`\<title\>.*-(.*?)\</title\>`; }); if (img.get() = null) { console.log("地址输入有误") return; } import inet.url; //table.push(lists, url) console.log("开始采集", url) var img_list = img_get(url) var title = img.get().title; var name = inet.url.getFileName(url); for (k, v in img_list) { //console.log(v) var http = web.rest.client() var img = http.get(v); var msg = string.save(path++"\"++title++"\"++name++"\"++k++".jpg",img); console.log(name++"第"++k++"张", msg) } console.log(url, '采集完成\r\n') url = console.askYesNo("是否继续采集,按Y键继续,按N键取消") ? (img.get().next) : null } console.log("全部采集完成") //return lists; }; var url = "http://unicornwj.lofter.com/post/33a459_effbd7ee"; lofter_list(url) console.pause()
感谢: aar培训群的 撒旦微笑 提供
登录后方可回帖