Obtain the weather code of www.weather.com.cn in JSON format in ASP.

Source: Internet
Author: User

Baidu has gone through it and found some other methods to improve it.
Get weather URL: Weather.
Because it is written into the cookie record that day weather, all need to browse under the site.
JS Code : Copy code Code: 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" pai.html (rd_cookie_info );
}
})

function getdata (URL)
{< BR >$. ajax ({
type: "Get",
cache: "false",
URL: "ajaxget. ASP ",
data:" url = "+ URL,
datatype:" html ",
error: function () {$ ("# Weather" ).html ("failed to read... 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 year, month, and day
getinfo + = result. weatherinfo. week + ""; // day of the week
getinfo + = "
"; // line feed
getinfo + = result. weatherinfo. city; // get the city name
getinfo + = "" // weather picture 1
getinfo + = ""; // weather Image 2
getinfo + = result. weatherinfo. weather1 + ""; // weather condition
getinfo + = result. weatherinfo. temp1; // temperature
$. cookie (cookie_info, getinfo, {path: '/', expires: date});
$ ("# Weather" pai.html (getinfo );
}< BR >});
}

HTML code:Copy codeThe Code is as follows: <Div id = "Weather" style = "font-size: 12px;"> </div>

This is a common ASP crawling on the network. Of course, it can also be replaced with. Net crawling or other. Attached demo.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.