asp下以Json获取中国天气网天气的代码

来源:asp之家 时间:2011-03-06 11:01:00 

百度了一下,找了点别人的方法改进了一下。 获取天气网址:http://www.weather.com.cn/html/weather/101210701.shtml这里是温州的,当然其他城市自己搜索一下,换一下ID。

由于是写入cookies记录当天天气,所有需要在站点下浏览。

js代码:

代码如下:

var Url=escape("http://m.weather.com.cn/data/101210701.html"); 
var COOKIE_info = "COOKIE_info"; 
var date = new Date(); 
var Hours=24-date.getHours()-1; 
var Mins=60-date.getMinutes()-1; 
var Secs=60-date.getSeconds(); 
date.setTime(date.getTime() + (1 * Hours * 60 * 60 * 1000) + (1 * 1 * Mins * 60 * 1000) + (1 * 1 * 1 * Secs * 1000)); 
var RD_cookie_info= $.cookie(COOKIE_info); 
$(function(){ 
if(RD_cookie_info==null) 

Getdata(Url); 

else{ 
$("#weather").html(RD_cookie_info); 

}) 

function Getdata(Url) 

$.ajax({ 
type:"GET", 
cache: "false", 
url: "AjaxGet.asp", 
data:"Url="+Url, 
dataType: "html", 
error: function(){$("#weather").html("读取失败...请刷新重试!");}, 
success: function(json){ 
var t = '('+json+')'; 
var result = eval(t); 
var Getinfo=""; 
Getinfo+=result.weatherinfo.date_y+" ";//年月日 
Getinfo+=result.weatherinfo.date+" ";//农历年月日 
Getinfo+=result.weatherinfo.week+" ";//星期几 
Getinfo+="<br />";//换行 
Getinfo+=result.weatherinfo.city;//获取城市名称 
Getinfo+=" <img src=\"http://m.weather.com.cn/img/c"+result.weatherinfo.img1+".gif\"/> "//天气图片1 
Getinfo+="<img src=\"http://m.weather.com.cn/img/c"+result.weatherinfo.img2+".gif\"/> ";//天气图片2 
Getinfo+=result.weatherinfo.weather1+" ";//天气情况 
Getinfo+=result.weatherinfo.temp1;//温度 
$.cookie(COOKIE_info,Getinfo, { path: '/', expires: date }); 
$("#weather").html(Getinfo); 

}); 

html代码:

代码如下:

<div id="weather" style="font-size:12px;"></div> 

这个是用网络上常见的asp抓取,当然也可以换成.net抓取或者其他。附上demo。

下载地址:json_weather.rar (24.79 KB)

标签:Json,天气网,天气
0
投稿

猜你喜欢

  • .NET中获取程序根目录的常用方法介绍

    2023-07-09 19:52:41
  • 详解如何使用beego orm在postgres中存储图片

    2024-04-25 15:14:46
  • Python使用tkinter模块实现推箱子游戏

    2022-12-06 08:27:49
  • Python中函数带括号和不带括号的区别及说明

    2023-01-23 05:23:28
  • SQL SERVER查询所有数据库名,表名,和字段名的语句

    2012-01-05 19:25:26
  • python基础知识之字典(Dict)

    2023-08-25 20:01:44
  • python3.x+pyqt5实现主窗口状态栏里(嵌入)显示进度条功能

    2021-12-29 06:55:13
  • 关于Python字符串显示u...的解决方式

    2021-12-21 18:58:58
  • Java中@Pattern注解常用的校验正则表达式学习笔记

    2022-08-07 11:12:10
  • 如何使用Maxwell实时同步mysql数据

    2024-01-18 01:43:23
  • 解决python运行效率不高的问题

    2023-04-01 05:31:36
  • SQL Server误区30日谈 第13天 在SQL Server 2000兼容模式下不能使用DMV

    2024-01-13 18:34:25
  • Python接口自动化之request请求封装源码分析

    2023-12-29 02:42:32
  • python Gunicorn服务器使用方法详解

    2021-09-06 00:35:08
  • PHP与Web页面交互操作实例分析

    2023-09-05 14:43:16
  • 富文本编辑器的基本原理与实践

    2008-06-13 13:28:00
  • MySQL数据库备份恢复的两个实用方法

    2008-12-31 15:09:00
  • Python OpenCV 针对图像细节的不同操作技巧

    2021-08-13 01:29:22
  • Python 字符串操作详情

    2023-02-04 19:03:59
  • 极简主义网站设计:寓丰富于简单

    2009-12-07 21:37:00
  • asp之家 网络编程 m.aspxhome.com