TypeError:Cannot read property 'type' of undefined
大搜给的结果是“ 类型错误:无法读取未定义的属性“type”
type 不要轻易修改,在修改之前请提前做好备份,以免无法挽回,
导致这种错误的原因有很多,首先要确认代码的正确性,可以参考以下代码,逐步排渣,保证没有错误,
1 {
2 title:'重庆',
3 source:'正在采集',
4 name:'cqssc',
5 enable:true,
6 timer:'cqssc',
7 option:{
8 host:"apiose.mycss.me",
9 timeout:50000,
10 path: '/xml.php?type=cqssc',
11 headers:{
12 "User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "
13 }
14 },
15 parse:function(str){
16 try{
17 str=str.substr(0,200);
18 var reg=/<row expect="([\d\-]+?)" opencode="([\d\,]+?)" opentime="([\d\:\- ]+?)"/;
19 var m;
20 if(m=str.match(reg)){
21 return {
22 type:1,
23 time:m[3],
24 number:m[1],
25 data:m[2]
26 };
27 }
28 }catch(err){
29 throw('解析数据不正确');
30 }
31 }
32 },
以上参数解释:
host:采集源地址的 域名或者iP
timeout:设置采集超时时间 50000就是50秒
path:就是采集源的具体路径了。
var reg 后面就抓取 XML格式的规则
type:就是菜种编号。
time: 调取的xml里面的时间
number:调取的xml里面的 期数
data:调取的xml里面的 号码。
作者:Alone°李道长ご