php根据接口获取天气
程序员文章站
2022-05-13 17:02:48
...
从网上找到一个大众的常用的天气接口:
上海:“ http://www.weather.com.cn/adat/cityinfo/101020100.html”
返回json子串:
内容格式倒是正确,信息也比较全, 可是没有指定日期的方式获取。
问题:
① 如何获取上海 当天和7天内的天气信息?
或者
② 能用正则将中国天气网的信息匹配出来?
url: http://www.weather.com.cn/weather/101020100.shtml
上海:“ http://www.weather.com.cn/adat/cityinfo/101020100.html”
返回json子串:
{"weatherinfo":{"city":"上海","city_en":"shanghai","date_y":"2014年3月4日","date":"","week":"星期二","fchh":"11","cityid":"101020100","temp1":"11C~6C","temp2":"10C~5C","temp3":"8C~4C","temp4":"8C~6C","temp5":"8C~6C","temp6":"10C~5C","tempF1":"51.8F~42.8F","tempF2":"50F~41F","tempF3":"46.4F~39.2F","tempF4":"46.4F~42.8F","tempF5":"46.4F~42.8F","tempF6":"50F~41F","weather1":"小雨转多云","weather2":"多云转阴","weather3":"小雨","weather4":"小雨","weather5":"小雨转阴","weather6":"多云","img1":"7","img2":"1","img3":"1","img4":"2","img5":"7","img6":"99","img7":"7","img8":"99","img9":"7","img10":"2","img11":"1","img12":"99","img_single":"7","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级转北风4-5级","wind2":"北风4-5级转东北风3-4级","wind3":"东风4-5级","wind4":"东风转东北风4-5级","wind5":"东北风3-4级","wind6":"东北风转东风3-4级","fx1":"东北风","fx2":"北风","fl1":"3-4级转4-5级","fl2":"4-5级转3-4级","fl3":"4-5级","fl4":"4-5级","fl5":"3-4级","fl6":"3-4级","index":"较冷","index_d":"建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。","index48":"较冷","index48_d":"建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。","index_uv":"最弱","index48_uv":"最弱","index_xc":"不宜","index_tr":"适宜","index_co":"较舒适","st1":"10","st2":"3","st3":"9","st4":"2","st5":"7","st6":"2","index_cl":"不宜","index_ls":"不宜","index_ag":"易发"}}
内容格式倒是正确,信息也比较全, 可是没有指定日期的方式获取。
问题:
① 如何获取上海 当天和7天内的天气信息?
或者
② 能用正则将中国天气网的信息匹配出来?
url: http://www.weather.com.cn/weather/101020100.shtml
今天
3日
小雨
16C
13C
微风
明天
4日
小雨
23C
15C
微风
后天
5日
雷阵雨
21C
13C
微风
周一
6日
中雨转小雨
15C
10C
3-4级
周二
7日
中雨
13C
8C
3-4级
周三
8日
中雨转小雨
13C
9C
微风
周四
9日
阴
14C
9C
微风