Currently, there are many websites that provide weather forecast services. Generally, they are used directly on their own websites. Some websites provide Web service interfaces.
- Common Regular Expressions:The common method to reference weather forecasts is to use regular expressions to parse the weather forecasts of a specified website. This method has some drawbacks: 1. the HTML format of a personal website has changed. YourProgramYou need to modify it. 2. It is not easy to write the parsed regular expressions. 3. Access to others' websites for each resolution. When an exception occurs on others' websites, your program may be dragged down. Of course, you can solve some problems from your application process.
- Web service interface:This is of course the first choice. Generally, websites that provide Web service interfaces are relatively stable.
If your website only needs to display the weather forecast for one region, use it directly. If you need to display the weather forecast for multiple regions, you may need to create your own IP address library. On that day, I saw that QQ provided some such services, So I simply studied it and found several useful interfaces. Among them, I am most satisfied that these interfaces are implemented in JavaScript and can be easily compatible with various website systems. However, the encoding format is gb2312 ~
I use jquery to call, and all calls are based on the results of http://minisite.qq.com/js/j.minisite.weather.js research.
Obtain the region and IP address of the current Browser:
$ J. getscript ("http://fw.qq.com: 80/IPaddress", function (){
If (typeof ipdata! = "Undefined "){
// Yoyosite. Cookie. Set ("current_ip", ipdata [2] + ',' + ipdata [3]);
Alert (ipdata );
}
});
I have simply encapsulated the current weather. Here I only describe how to use it (......, This weather forecast is not accurate ):
<Script language = "JavaScript" src = "http://www.greatmoo.com/untest/samples/js/jquery.js"> </SCRIPT>
<Script language = "JavaScript" src = "http://www.greatmoo.com/untest/samples/weather/weather.js"> </SCRIPT>
<Div id = "weather_content"> </div>
<Script language = "JavaScript">
Weather. INIT ("weather_content ");
</SCRIPT>
The calling method is very simple.Weather_contentThis keyword.
application instance: Success.