MAS接口常遇问题

1、运行地址(格式)如图
http://127.0.0.1:9090/xxx/xxx/default/rrrff

QQ图片20151106173138

2、MAS结构
文件元素的查找范围 Robot
Robot,function(des){
//add your web html pretreatment code to decrease DOM parsing time.
var s=des.indexOf(‘<div class=”view_ti”>’);
var e=des.indexOf(‘<div style=” clear:both; height:10px;”>’);
//substring 范围界定
return des.substring(s,e);
//return des;
}

3、取到中间字段篇幅
function list(tTit){
var text = “<font color=gray>”;
var endText = “</font>”;
var ss= tTit.indexOf(text);
var ee=tTit.indexOf(endText);
return tTit.substring(ss+text.length,ee);
}
tit.push(list(tTit)); //push的是运行完的结果

4、列表页和详情页结合轮播图代码汇总
思路:先调取列表,在详情页面解决图片地址。利用索引值id调取背景图片。
var namearr = [];
var imgArr = [];
function newsCarousel(){
$toast(‘数据加载中…’);
$.getJSON(‘http://127.0.0.1:8087/xxx/xxx/default/list’, function(data){
//新闻图片轮播
if (data.status == ‘0’ && data.data && data.data.length) {
$closeToast();
var dataLen = data.data;
var tmpl = ‘<div class=”ub-fh” ontouchstart=”zy_touch(\’\’)” onclick=”openNewWin(\’news_articlecommon\’,\’news_articlecommon.html\’);”>’
+'<div id=”img_${index:}” class=”ub ub-f1 ub-imgnews newsban ub-ae uh-for1 ${cb:name}” style=”background-image:url(http://www.sinosure.com.cn/sinosure/xwzx/xbdt/images/20140829/32045.jpg);”></div>’
+'</div>’;
var s = zy_tmpl(tmpl, dataLen, zy_tmpl_count(dataLen), function(a, b){
namearr.push(a.name);
$closeToast();
});
$$(‘slider’).innerHTML = s;
//显示小点
var str = ”;
for (var i = 0; i < dataLen.length; i++) {

if (i == 0) {
str += ‘<div id=”num’ + i + ‘” class=”uc-a-for1 uwh-for1 c-wh3 umar-r-for”></div>’;
}
else {
str += ‘<div id=”num’ + i + ‘” class=”uc-a-for1 uwh-for1 c-gra-for2 umar-r-for”></div>’;
}
}
$$(‘proint’).innerHTML = str;

//滑动时当前图片的小点颜色为蓝色
var slider = new zySlide(“slider”, “H”, function(){
var cur = slider.currentPoint;
var length = slider.maxPoint;
for (var n = 0; n <= length; n++) {
if (n == cur) {
$$(“num” + n).className = ‘uc-a-for1 uwh-for1 c-wh3 umar-r-for’;
}
else {
$$(“num” + n).className = ‘uc-a-for1 uwh-for1 c-gra-for2 umar-r-for’;
}
}
$$(‘title’).innerHTML = namearr[cur];
}, false, function(e){});

for(var j=0;j<5;j++){
var url = dataLen[j].href;
$.getJSON(‘http://127.0.0.1:8087/xxx/xxx/default/fff?index=’+j+’&url=’+url, function(data1){
$$(‘img_’+data1.index).style.backgroundImage = ‘url(‘+data1.data[0].src+’)’;
$$(‘title’).innerHTML=data1.title;
});
}
}
});
}
Mas接口 info
var MEAP = require(“meap”);

function run(Param, Robot, Request, Response, IF){
LOG(“Param.params.index”,Param.params.index);
var option={
method : “GET”,
url: Param.params.url,
index:Param.params.index,
Cookie : “true”,
Charset:”gb2312″
};

MEAP.AJAX.Runner(option,function(err,res,data){
if(!err)
{
//Add your normal handling code
MEAP.PARSER.Runner(“HTML”,res.text, function(err,DOM){
if(!err && DOM){
var arr=[];
var t=DOM.getElementsByTagName(‘div’);
var tit =t.length;
var tit=t[0].innerHTML;
// var con=t[1].text();
// var tit =t[0].innerHTML;
var con =t[1].innerHTML;

var timg=DOM.getElementsByTagName(‘IMG’);

for( var i=0;i<timg.length;i++){
var url =”http://www.sinosure.com.cn”+timg[i].src;
if(timg==”||timg==undefined){
//url=”http://www.sinosure.com.cn/sinosure/xwzx/xbdt/images/20140827/32026.jpg”;
break;
}
var src = url.replace(“file:///D:/”,”/”);
arr.push(src);
}

//Add your DOM handling code

var answerStr = JSON.stringify(
{
status: 0,
title: tit,
content: con,
index:Param.params.index,
data: arr
});
var o = JSON.parse( answerStr);
Response.end(JSON.stringify(o));
}
else {
Response.end(JSON.stringify({
status: 1,
msg: “异常”

}));
}
});
}
else {
Response.end(JSON.stringify({
status: 1,
msg: “异常”
}));
}

},Robot,function(des){
var s=des.indexOf(‘<div class=”view_ti”>’);
var e=des.indexOf(‘<div style=” clear:both; height:10px;”>’);
return des.substring(s,e);
});
}

exports.Runner = run;
Mas接口 list
var MEAP = require(“meap”);

function run(Param, Robot, Request, Response, IF){

var option={
method : “GET”,
url: “http://www.sinosure.com.cn/sinosure/xwzx/xbdt/default.html”, //列表页抓取页面
Cookie : “true”,
Charset:”gb2312″
};

MEAP.AJAX.Runner(option,function(err,res,data){
if(!err)
{
//Add your normal handling code
MEAP.PARSER.Runner(“HTML”,res.text, function(err,DOM){
if(!err && DOM){
var arr=[];
//var tit=[];
var oLi=DOM.getElementsByTagName(‘a’);
function list(tTit){
var text = “<font color=gray>”;
var endText = “</font>”;
var ss= tTit.indexOf(text);
var ee=tTit.indexOf(endText);
return tTit.substring(ss+text.length,ee);
}
for(var i=21;i<26;i++){
var obj={};
obj.title=list(oLi[i].innerHTML);
obj.href=”http://www.sinosure.com.cn”+oLi[i].attributes[‘href’].value;
arr.push(obj);
}
var answerStr = JSON.stringify(
{
status: 0,
//title:tit,
data: arr
});
var o = JSON.parse( answerStr);
// eval(“var answerStr = ‘”+JSON.stringify(o)+”‘;”);
Response.end(JSON.stringify(o));
}
else {
Response.end(JSON.stringify({
status: 1,
msg: “异常”

}));
}
});
}
else {
Response.end(JSON.stringify({
status: 1,
msg: “异常”
}));
}

},Robot,function(des){
//add your web html pretreatment code to decrease DOM parsing time.
var s=des.indexOf(‘<div class=”news_gray_k”>’);
var e=des.indexOf(‘<div class=”gradual”>’);
//var img=des.indexOf(‘<img’);
//substring 范围界定
return des.substring(s,e);
//return des;
});
}

exports.Runner = run;

发表评论

电子邮件地址不会被公开。