js获取新浪天气接口

 1 <!doctype html>
 2 <html class="no-js fixed-layout">
 3 <head>
 4   <meta charset="utf-8">
 5   <meta http-equiv="X-UA-Compatible" content="IE=edge">
 6   <title>天气</title>
 7 </head>
 8 <body>
 9 <div class="top-tool">
10     <span id="sj"></span><span id="weather"><img width="16px" height="16px" src=""></span>
11       <form action="/Search" method="get" id="qform" class="search-form" style="text-align:right;display:inline;float:right;padding-right:10px;" target="_blank">
12         <span class="round">
13         <input name="keywords" id="q" tabindex="1" class="input-key search-q ac_input" value="" maxlength="100" autocomplete="off">
14         </span> <span class="button">
15         <input type="submit" tabindex="2" id="su" value="搜&nbsp;&nbsp;索" class="ui-btn" style="padding: 0px 5px;">
16         </span>
17       </form>
18 </div>
19 <script type="text/javascript" src="jquery-1.8.3.min.js"></script>
20 <script type="text/javascript">
21         function showLocale(objD) {
22             var str, colorhead, colorfoot;
23             var yy = objD.getYear();
24             if (yy < 1900) yy = yy + 1900;
25             var MM = objD.getMonth() + 1;
26             if (MM < 10) MM = ‘0‘ + MM;
27             var dd = objD.getDate();
28             if (dd < 10) dd = ‘0‘ + dd;
29             var hh = objD.getHours();
30             if (hh < 10) hh = ‘0‘ + hh;
31             var mm = objD.getMinutes();
32             if (mm < 10) mm = ‘0‘ + mm;
33             var ss = objD.getSeconds();
34             if (ss < 10) ss = ‘0‘ + ss;
35             var ww = objD.getDay();
36             if (ww == 0) colorhead = "";
37             if (ww > 0 && ww < 6) colorhead = "";
38             if (ww == 6) colorhead = "";
39             if (ww == 0) ww = "星期日";
40             if (ww == 1) ww = "星期一";
41             if (ww == 2) ww = "星期二";
42             if (ww == 3) ww = "星期三";
43             if (ww == 4) ww = "星期四";
44             if (ww == 5) ww = "星期五";
45             if (ww == 6) ww = "星期六";
46             colorfoot = ""
47             str = colorhead + yy + "-" + MM + "-" + dd + " " + hh + ":" + mm + ":" + ss + "  " + ww + colorfoot;
48             return (str);
49         }
50         function tick() {
51             var today;
52             today = new Date();
53             document.getElementById("sj").innerHTML = showLocale(today);
54             window.setTimeout("tick()", 1000);
55         }
56         tick();
57
58
59         function findWeather() {
60             var cityUrl = ‘http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js‘;
61             $.getScript(cityUrl, function (script, textStatus, jqXHR) {
62                 var citytq = remote_ip_info.city; // 获取城市
63
64                 citytq = "郑州";
65                 var url = "http://php.weather.sina.com.cn/iframe/index/w_cl.php?code=js&city=" + citytq + "&day=0&dfc=3";
66                 $.ajax({
67                     url: url,
68                     dataType: "script",
69                     scriptCharset: "gbk",
70                     success: function (data) {
71                         var _w = window.SWther.w[citytq][0];
72                         var _f = _w.f1 + "_0.png";
73                         if (new Date().getHours() > 17) {
74                             _f = _w.f2 + "_1.png";
75                         }
76                         var img = "<img width=‘16px‘ height=‘16px‘ src=‘http://i2.sinaimg.cn/dy/main/weather/weatherplugin/wthIco/20_20/" + _f
77                 + "‘ />";
78                         var tq = "今日天气 : " + citytq + " " + img + " " + _w.s1 + " " + _w.t1 + "℃~" + _w.t2 + "℃  " + _w.d1 + _w.p1 + "级";
79                         $(‘#weather‘).html(tq);
80                     }
81                 });
82             });
83         }
84         findWeather()
85     </script>
86 </body>
87 </html>
时间: 2024-08-01 23:53:12

js获取新浪天气接口的相关文章

【API】新浪天气接口 Beta

新浪天氣接口那是公認的好,可是百度之後發現很簡陋,所以自己寫了工具類,此處幫忙測試下其中的天氣接口,看有哪些地方要改進的. Jar 名称:          NonentityUtil Class 名称:       SinaWeatherUtil,新浪天氣 Util 類 方法名:            getWeatherByCity(String city,int forecastDays),根據城市獲取天氣 輸入參數:         city,城市,拼音或者漢語([BUG]輸入拼音返回的

获取新浪天气api显示天气情况(转)

直接上一个html的demo <!doctype html> <html class="no-js fixed-layout"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>天气</title> </h

(转)利用libcurl获取新浪股票接口, ubuntu和openwrt实验成功(三)

1.  利用 CURLOPT_WRITEFUNCTION 设置回调函数, 利用 CURLOPT_WRITEDATA 获取数据指针 官网文档如下 CALLBACK OPTIONS CURLOPT_WRITEFUNCTION Pass a pointer to a function that matches the following prototype: size_t function( char *ptr, size_t size, size_t nmemb, void *userdata); 

【Servlet】Javaweb中,利用新浪api接口,获取IP地址,并获取相应的IP归属地

这里之所以调用新浪api接口,主要是可以避免我们在本地存放一个ip归属地库, 同时,我们在本地要存放用户的ip,仅仅存放其ip就可以了,无须存放其归属地,节省一个字段. 如下图,写一个带有获取客户端IP地址的网页: 首先,在Eclipse的目录结构如下: 里面除了servlet的支持包之外,就一个.jsp与一个.java. 其中这里用到Servlet3.0,因此web.xml没有任何东西: <?xml version="1.0" encoding="UTF-8"

【php】利用新浪api接口与php获取远程数据的方法,获取IP地址,并获取相应的IP归属地

本文与<[Servlet]Javaweb中,利用新浪api接口,获取IP地址,并获取相应的IP归属地>(点击打开链接)为姊妹篇,只是后端编程语言换成了php. 做出同样的效果,打开页面,得到客户端的ip,并获取利用新浪api接口获取此ip的归属地. 可以看到,在IE6也是相当正常的. 目录结构如下,非常简单,同样就两个文件,其实如果你愿意,写成一个php文件也可以,但是显示层和逻辑业务层还是不混在一起为好吧? 唯一值得注意的是,这两个文件打死也不能一个叫ipGet.php,ipGet.html

用Selenium抓取新浪天气

(1)用Selenium抓取新浪天气 系统环境: 操作系统:macOS 10.13.6 python :2.7.10 用虚拟环境实现 一.创建虚拟环境: mkvirtualenv --python=/usr/bin/python python_2 二.激活虚拟环境: workon python_2 三.安装Selenium pip install Selenium 四.安装firefox的Selenium补丁文件: brew install geckodriver 五.在~/.bash_prof

Python如何调用新浪api接口的问题

前言:这些天在研究如何调用新浪开放平台的api分析新浪微博用户的数据 成果:成功调用了新浪api获取了用户的一些个人信息和无数条公共微博 不足:新浪开放平台访问有限制,返回的数据着实有限,不足以分析问题,真的要分析问题还是得个人写爬虫 下面是调用新浪开放api的过程: 第一步:按这个做就行 http://www.cnblogs.com/dhsunny/p/3578399.html?utm_source=tuicool&utm_medium=referral 其中有一不那个新浪api测试工具是打不

scrapy新浪天气

一.实验说明 1. 环境登录 无需密码自动登录,系统用户名shiyanlou 2. 环境介绍 本实验环境采用带桌面的Ubuntu Linux环境,实验中会用到桌面上的程序: LX终端(LXTerminal): Linux命令行终端,打开后会进入Bash环境,可以使用Linux命令 Scrapy:Scrapy是一个为了爬取网站数据,提取结构性数据而用Python编写的应用框架. 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中. GVim:非常好用的编辑器,最简单的用法可以参考课程V

[iOS微博项目 - 2.1] - 获得新浪授权接口

A.如何获得新浪的授权接口 登陆新浪的开放平台 注册新浪账号 创建应用 获得应用id和请求地址 查阅相关API 关联需要进行测试的账号 1.登陆开放平台 http://open.weibo.com 2.注册账号 (略) 3.创建应用 4.填写开发者资料 5.创建应用 5.取得应用的App Key和App Secret B.新浪微博API 1.OAuth授权API 上面的redirect_uri也是必填参数,需要在"我的应用"管理页中填写 随便填一个就可以了,其实就是授权成功或者失败的跳