I will make a weather forecast in the past two days. I remember that when I used the .net version, I used to grab Baidu weather and write it into txt, and then read it. Over time, there are a lot of txt files. It doesn't feel very good. I searched Baidu and found some other people's methods to improve it.
Get the weather website: http://www.weather.com.cn/html/weather/101210701.shtml This is Wenzhou. Of course, search for other cities and change the ID.
Since cookies are written to record the weather of the day, you need to browse the site.
js code:
Copy the code code as follows:
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;
varSecs=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(Reading failed... Please refresh and try again!);},
success: function(json){
var t = '('+json+')';
var result = eval(t);
var Getinfo=;
Getinfo+=result.weatherinfo.date_y+ ;//Year, month and day
Getinfo+=result.weatherinfo.date+ ;//Lunar calendar year, month and day
Getinfo+=result.weatherinfo.week+ ;//Day of the week
Getinfo+=<br />;//Line break
Getinfo+=result.weatherinfo.city;//Get the city name
Getinfo+= <img src=/http://m.weather.com.cn/img/c+result.weatherinfo.img1+.gif//> //Weather picture 1
Getinfo+=<img src=/http://m.weather.com.cn/img/c+result.weatherinfo.img2+.gif//> ;//Weather picture 2
Getinfo+=result.weatherinfo.weather1+ ;//Weather conditions
Getinfo+=result.weatherinfo.temp1;//Temperature
$.cookie(COOKIE_info,Getinfo, { path: '/', expires: date });
$(#weather).html(Getinfo);
}
});
}
html code:
Copy the code code as follows:
<div id=weather style=font-size:12px;></div>
This is using the common asp crawling on the Internet. Of course, it can also be replaced by .net crawling or other.