Copy codeThe Code is as follows:
<? Php
Header ("content-type: text/html; charset = UTF-8 ");
$ Weather = file_get_contents ("http://www.weather.com.cn/data/sk/101280601.html ");
Echo $ weather;
?>
Copy codeThe Code is as follows:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gbk"/>
<Style type = "text/css">
. All span {font: bold 30px/50px ""; color: red ;}
</Style>
<Title> weather forecast </title>
</Head>
<Body>
<Div class = "all">
Here is: <span class = "place"> city </span>,
The temperature is <span class = "temp"> temperature </span>,
Wind direction: <span class = "wind"> wind direction </span>,
Wind power: <span class = "windPower"> Wind Power </span>
</Div>
<Script type = "text/javascript" src = "http: // 127.0.0.1/jquery. js"> </script>
<Script type = "text/javascript">
$ (Function (){
$. Ajax ({
// Request address
Url: "http: // 127.0.0.1/weather. php ",
// The function executed after the request is successful
Success: function (data ){
// Parse the returned data with eval () and convert the string to JSON format
Var oD = eval ('+ data + ')');
// Get element with jquery-1.8.2
Var $ place = $ (". place "),
$ Temp = $ (". temp "),
$ Wind = $ (". wind "),
$ WindPower = $ (". windPower ");
// Place the returned data to the corresponding location
Using place.html (oD ["weatherinfo"] ["city"]);
$Temp.html (oD ["weatherinfo"] ["temp"] + "° ");
$Wind.html (oD ["weatherinfo"] ["WD"]);
Export windpower.html (oD ["weatherinfo"] ["WS"]);
}
});
})
</Script>
</Body>
</Html>