Php crawls weather forecast interface data, ask for advice National Meteorological Administration free weather forecast interface (Shenyang): Workshop. I don't know how to get this json using php. I found the following code on the Internet: php crawls the weather forecast interface data.
National Meteorological Administration free weather forecast interface (Shenyang): http://www.weather.com.cn/data/cityinfo/101010100.html
This interface provides a weather forecast data in json format.
I don't know how to get this json using php. I found the following code on the Internet:
However, the httpGetRequest function is a custom function, and the prototype of this function is not released online! Please kindly advise! Json weather forecast
------ Solution --------------------
$url = 'http://www.weather.com.cn/data/cityinfo/101070101.html';
$s = file_get_contents($url);
print_r(json_decode($s, true));
Array
(
[Weatherinfo] => Array
(
[City] => Shenyang
[Cityid] = & gt; 101070101
[Temp1] => 10 ℃
[Temp2] =>-2 ℃
[Weather] => multi-cloud
[Img1] => d1.gif
[Img2] => n1.gif
[Ptime] => 08:00
)
)
------ Solution --------------------
HttpGetRequest does not need to be ignored. The purpose is to capture the text. it is just a means. you can write it by yourself.
Directly obtain the file_get_contents from the moderator. to save traffic, use curl or socket to send a compression request.
Use file_get_contents to complete the work, and wait for time to learn about curl, socket... and then optimize it.