This article is a mirror article of machine translation, please click here to jump to the original article.

View: 17668|Reply: 1

[Source] Get weather forecasts with Python

[Copy link]
Posted on 6/5/2018 3:27:41 PM | | | |
Weather Forecast Interface:http://www.weather.com.cn/data/sk/101010100.html
(101010100 is the code for Beijing weather)
Interface JSON field description:

city "Beijing" // City  
cityid "101010100" // city code  
temp "17" // current temperature  
WD "East Wind" // Wind direction  
WS "Level 2" // Wind  
SD "70%" // Relative humidity  
WSE "2" // Wind  
time "14:20" // Update time  
isRadar "1" // with radar maps   
Radar "JC_RADAR_AZ9010_JB" // Radar map addresshttp://www.weather.com.cn/html/radar/JC_RADAR_AZ9010_JB.shtml  


XML Interface Root Node:The hyperlink login is visible.

The main function of the interface is to recursively obtain the city code of thousands of counties or more in the country, for example: The XML address of Shanghai is:The hyperlink login is visible.The XML address in Shandong is:The hyperlink login is visible.


Get list information on major cities across the country + abroad, 8763 cities.URL:The hyperlink login is visible.

Steps: Get the code of the list of all cities, and then get the corresponding code by the city name, access the weather interface, and get the weather of the city.



The python code is as follows:

Outcome:

C:\project\web\app1>cd c:\project\web\app1 && cmd /C "set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && python C:\Users\itsvse_pc\.vscode\extensions\ms-python.python-2018.4.0\pythonFiles\PythonTools\visualstudio_py_launcher_nodebug.py c:\project\web\app1 56150 34806ad9-833a-4524-8cd6-18ca4aa74f14 RedirectOutput,RedirectOutput c:\project\py\demo.py "
http://www.itsvse.com by:小渣渣
Start processing Data processing is complete!
Get weather success
{'weatherinfo': {'city': 'Jining', 'cityid': '101120701', 'temp': '23.6', 'WD': 'South Wind', 'WS': 'Less than 3', 'SD': '67%', 'AP': '1002.3hPa', 'njd': 'No live situation', 'WSE': ' <3', 'time': '18:00', 'sm': '1.4', 'isRadar': '0', 'Radar': ''}}
Weather in Jining
Temperature: 23.6
Wind direction: south wind
Wind: less than 3 levels

Resources

Python implements XML file parsing:https://www.itsvse.com/thread-4823-1-1.html

Basic use of requests in python crawlers:The hyperlink login is visible.

Finally, attach the code:

demo.py (1.85 KB, Number of downloads: 2)





Previous:VS Code code quick formatting shortcuts
Next:TCP port communication connection demo
Posted on 6/13/2018 9:07:18 AM |
Thanks for sharing.
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com