马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?点击注册
x
本帖最后由 饭团啊哒 于 2013-6-6 23:53 编辑
{"weatherinfo":{"city":"北京","city_en":"beijing","date_y":"2013年6月6日","date":"","week":"星期四","fchh":"18","cityid":"101010100","temp1":"19℃~24℃","temp2":"20℃~24℃","temp3":"19℃~21℃","temp4":"16℃~25℃","temp5":"16℃~27℃","temp6":"18℃~30℃","tempF1":"66.2℉~75.2℉","tempF2":"68℉~75.2℉","tempF3":"66.2℉~69.8℉","tempF4":"60.8℉~77℉","tempF5":"60.8℉~80.6℉","tempF6":"64.4℉~86℉","weather1":"小雨转中雨","weather2":"阵雨","weather3":"大雨转小雨","weather4":"阴转雷阵雨","weather5":"晴","weather6":"晴","img1":"7","img2":"8","img3":"3","img4":"99","img5":"9","img6":"7","img7":"2","img8":"4","img9":"0","img10":"99","img11":"0","img12":"99","img_single":"8","img_title1":"小雨","img_title2":"中雨","img_title3":"阵雨","img_title4":"阵雨","img_title5":"大雨","img_title6":"小雨","img_title7":"阴","img_title8":"雷阵雨","img_title9":"晴","img_title10":"晴","img_title11":"晴","img_title12":"晴","img_title_single":"中雨","wind1":"微风","wind2":"微风","wind3":"微风","wind4":"微风","wind5":"微风","wind6":"微风","fx1":"微风","fx2":"微风","fl1":"小于3级","fl2":"小于3级","fl3":"小于3级","fl4":"小于3级","fl5":"小于3级","fl6":"小于3级","index":"舒适","index_d":"建议着长袖T恤、衬衫加单裤等服装。年老体弱者宜着针织长袖衬衫、马甲和长裤。","index48":"舒适","index48_d":"建议着长袖T恤、衬衫加单裤等服装。年老体弱者宜着针织长袖衬衫、马甲和长裤。","index_uv":"最弱","index48_uv":"最弱","index_xc":"不宜","index_tr":"一般","index_co":"舒适","st1":"22","st2":"17","st3":"23","st4":"18","st5":"20","st6":"17","index_cl":"不宜","index_ls":"不宜","index_ag":"极不易发"}} 1. 假定我们要获取中文的城市名,那么我们需要知道北京左边和右边的固定的词(不随着检测城市或者天气的变化而变化),这里要获取的城市名为”北京”,而”北京”左右的情况是"city":"北京","city_en",左边的”city”和右边的”city_en”都是固定的,因此当想要单独获取中文城市名的时候,我们可以使用这对固定的词,不过请确保固定的词在整个内容里面是独一无二的. 2. 现在说说获取所使用的正则表达式,通常在开头写”(?siU)”-à 这代表着后面在获取信息的时候无视掉大小写、换行,并且返回第一个适配到的结果. ”(.*)”这个表示当左边和右边都匹配的话,就获取这个位置的信息. “.*”表示当左右两边都能匹配到的时候忽略掉中间的内容. 3. 然后我们获取”北京”这个词的写法就是-à (?siU)city":"(.*)","city_en,我叫这个检测块. 然后代码的写法就是: [GetWeatherInfo] Measure=Plugin Plugin=WebParser URL=http://m.weather.com.cn/data/101010100.html RegExp=(?siU)city":"(.*)","city_en.*week":"(.*)","fchh UpdateDivider=30 à这行通常是为了降低检测网页的频率,这样做是有好处的. StringIndex=1
此时是可以获取到”北京”这个词语的. 4. 假如我要同时获取”北京”和”星期四”呢,这时候可以在RegExp后面添加”.* week":"(.*)","fchh”即可.所以新的代码就是: [GetWeatherInfo] Measure=Plugin Plugin=WebParser URL=http://m.weather.com.cn/data/101010100.html RegExp=(?siU)city":"(.*)","city_en.*week":"(.*)","fchh UpdateDivider=30 à这行通常是为了降低检测网页的频率,这样做是有好处的. StringIndex=1
所以现在就可以总结出规律: RegExp是这么写的: (?siU)city":"(.*)","city_en.* week":"(.*)","fchh 粉红色 à 全局动作指令,告诉后面的小弟怎么对待字符串. 青绿色 à 表示要获取的文本左右两边的特征,通常是在不同的情况下都不变的. 灰色 à 表示需要获取的文本段,此文本段是变化的,所以用一个通用的符号表示. 橙黄色 à 表示放弃左右两边特征相符的文本段,相当于”+”,连接两个检测块. 5. 假如有很多个检测块的话,每个检测块都会返回一个匹配(如果成功的话),从代码的左边到右边依次序号为1、2、3… .要一一返回的话可以利用Webparser的子Measure,具体写法参见文档,每个子Measure之间只有”StringIndex=”后面的值不同,代表着母Measure中不同返回值的序号. 最后给个链接完整返回信息的解释(网上粘的): {"weatherinfo":{
//基本信息;
"city":"北京","city_en":"beijing",
"date_y":"2012年2月16日","date":"", "week":"星期四", "fchh":"11","cityid":"101010100",
//摄氏温度"temp1":"2℃~-7℃",
"temp2":"1℃~-7℃",
"temp3":"4℃~-7℃",
"temp4":"7℃~-5℃",
"temp5":"5℃~-3℃",
"temp6":"5℃~-2℃",
//华氏温度;
"tempF1":"35.6℉~19.4℉",
"tempF2":"33.8℉~19.4℉",
"tempF3":"39.2℉~19.4℉",
"tempF4":"44.6℉~23℉",
"tempF5":"41℉~26.6℉",
"tempF6":"41℉~28.4℉",
//天气描述;
"weather1":"晴",
"weather2":"晴",
"weather3":"晴",
"weather4":"晴转多云",
"weather5":"多云",
"weather6":"多云转阴",
//天气描述图片序号
"img1":"0",
"img2":"99",
"img3":"0",
"img4":"99",
"img5":"0",
"img6":"99",
"img7":"0",
"img8":"1",
"img9":"1",
"img10":"99",
"img11":"1",
"img12":"2",
"img_single":"0",
//图片名称;
"img_title1":"晴",
"img_title2":"晴",
"img_title3":"晴",
"img_title4":"晴",
"img_title5":"晴",
"img_title6":"晴",
"img_title7":"晴",
"img_title8":"多云",
"img_title9":"多云",
"img_title10":"多云",
"img_title11":"多云",
"img_title12":"阴",
"img_title_single":"晴",
//风速描述
"wind1":"北风3-4级转微风",
"wind2":"微风",
"wind3":"微风",
"wind4":"微风",
"wind5":"微风",
"wind6":"微风",
//风速级别描述
"fx1":"北风",
"fx2":"微风",
"fl1":"3-4级转小于3级",
"fl2":"小于3级",
"fl3":"小于3级",
"fl4":"小于3级",
"fl5":"小于3级",
"fl6":"小于3级",
//今天穿衣指数;
"index":"冷",
"index_d":"天气冷,建议着棉衣、皮夹克加羊毛衫等冬季服装。年老体弱者宜着厚棉衣或冬大衣。",
//48小时穿衣指数
"index48":"冷",
"index48_d":"天气冷,建议着棉衣、皮夹克加羊毛衫等冬季服装。年老体弱者宜着厚棉衣或冬大衣。",
//紫外线及48小时紫外线
"index_uv":"弱",
"index48_uv":"弱",
//洗车
"index_xc":"适宜",
//旅游
"index_tr":"一般",
//舒适指数
"index_co":"较不舒适",
"st1":"1",
"st2":"-8",
"st3":"2",
"st4":"-4",
"st5":"5",
"st6":"-5",
//晨练
"index_cl":"较不宜",
//晾晒
"index_ls":"基本适宜",
//过敏
"index_ag":"极不易发"}}
|