Php crawls weather forecast interface data.-php Tutorial

Source: Internet
Author: User
Php capture weather forecast interface data problems, ask for advice 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!


Reply to discussion (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
)

)

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.

In the code you paste, $ info is the data you get.

The moderator is the moderator. thank you very much! I would also like to thank snmr_com for its optimization suggestions!

The moderator is correct...

This interface is no longer updated and the retrieved data is incorrect.

Http://club.weather.com.cn/thread-555402-1-1.html

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.