1. Open Appcan IDE, file → New →mas service
2. New MAS Project
3. New MAS interface, access address http://mobile.163.com/special/chuangye/
4, modify the If.js under the If_cytznews
1varMeap=require ("MEAP");
2
3functionRun (Param, Robot, Request, Response, IF)
4{
5
6varoption={
7Method: "GET",
8URL: "http://mobile.163.com/special/chuangye/",
9Cookie: "True",
TenCharset: "gb2312"
One};
A
-MEAP. Ajax. Runner (option,function(Err,res,data) {
-if(!err)
the{
-//Add your normal handling code
-MEAP. PARSER. Runner ("HTML", Res.text,function(Err,dom) {
-if(!err && DOM)
+{
-//ADD your DOM handling code
+varResult=[];
AvarUl=dom.getelementsbytagname (' ul ');
atvarLi=ul[0].childnodes;
-varTitle= ', link= ', date= ';
- varobj={};
-varAtag= ";
- for(vari = 0; i<li.length;i++) {
- //datespan=li[0].getelementsbytagname (' span ') [0];
inDate=li[i].childnodes[0].innerhtml.replace (/\ (/, "). Replace (/\)/, ');
-ATAG=LI[I].CHILDNODES[1];
toLink=atag.href;
+title=atag.innerhtml;
-//Console.log (link,title);
theobj={
*Title:title,
$Href:link,
Panax NotoginsengDate:date
-}
theResult.push (obj);
+}
A//Console.log (li.length);
the}
+//Response.setheader ("Content-type", "text/html; Charset=utf-8 ");
-Response.setheader ("Content-type", "Application/json; Charset=utf-8 ");
$Response.End (json.stringify (result));
$//Response.End (data);
-});
-}
the Else
-{
Wuyi//ADD Your exception handling code
the}
-
Wu},robot,function(DES) {
-//Add your Web HTML pretreatment code to decrease DOM parsing time.
AboutvarStart=des.indexof (' <div class= ' content > ') + (' <div class= ' content ' > '). length;
$varEnd=des.indexof (' <div class= ' listpages ' > ');
-returnDes.substring (start,end). Replace (/<\/div>$/, ")
-. replace (/<span class=\ "dotline\" ><\/span>/ig, ')
-. replace (/<\/ul>\n\n<ul class=\ "list_f14d\" >/ig, ')
A. replace (/\n/g, ");
+});
the}
-
$Exports. Runner = run;
5. Right-click Mas.js and select "Run".
6. Enter Http://127.0.0.1:8082/xm150102/cytznews in the browser address bar
The final result is as follows:
Appcan Mas Interface Ajax