获取图片

admin2021-01-15  93

import console;
import web.json;
import string.html
import web.rest.client
  
_host = "https://www.todaybing.com";
_api = "https://www.todaybing.com/web/api";
  
var http = web.rest.client();
http.referer = _host
  
// 获取 token
var getToken = http.api(_host, "GET", function(ret) {
    var ret = string.match(ret, "s\s=\s(%{})")
    return web.json.parse(ret)[["tk"]];
})
  
// 获取列表
getList = function(data) {
    return http.api(_api,,function(ret){
        var list = {}
        var doc = string.html( ret )
        var content = doc.queryEles(['class'] = "media-content")
        for (i = 1; # content) {
            table.push(list, _host + content[i].href)
        }
        return list; 
    })(data); 
}
  
// 获取详情
getDetail = function(url) {
    return http.api(url, "GET", function(ret) {
        var addr = ""
        var ret = string.html(ret)
        var image = ret.queryEle(['class'] = "top-main-bg").style
        var address = ret.queryEle(['class'] = "text-sm").innerText()
        string.replace(address, ":+", function(s) {
            addr = addr + " " + s
        });
        return {
            url = url;
            addr = string.trim(addr);
            image = string.match(image, "\((.+)\)");
            title = ret.queryEle(tagName = "h2").innerText();
            time = ret.queryEle(tagName = "time").innerText();
            content = ret.queryEle(['class'] = "text-1").outerXml()
        };
    })()
}
  
console.showLoading("正在获取数据ing...")
  
// Post parameters
var data = {
    append = "list-home";
    paged = 1;
    token = getToken();
    action = "ajax_load_posts";
    page = "home";
}
  
// Get url list
var list = {}
for(i=1;3){
    data.paged = i
    var t = getList(data)
    table.push(list, table.pop(t,#t) )
}
  
// Get all detail
var details = {}
for (i = 1; #list) table.push(details, getDetail(list[i]))
  
// Save results to json
string.save("/images.json", web.json.stringify(details) )
console.dumpJson( details )
  
console.pause(true);
转载请注明原文地址: http://www.aardio.net/read-134.html
最新回复(0)