By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,826 Members | 2,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,826 IT Pros & Developers. It's quick & easy.

how to get current weather information to my program

P: 2
Hi all! I am new to python so what I am asking might be ambitious, but I want to know if there is a way to take information from the national weather service an use it as ambient tempertures to calculate heat trabsfer problems? Any help is greatly apperciated!
Dec 21 '14 #1

✓ answered by bvdet

Using the url suggested by RachelCook and a specific locale, the following will extract the high and low temperatures.
Expand|Select|Wrap|Line Numbers
  1. >>> from urllib import urlopen
  2. >>> from bs4 import BeautifulSoup
  3. >>> url = "http://weather.weatherbug.com/MN/Wahkon-weather.html?zcode=z6286&zip=56386"
  4. >>> soup = BeautifulSoup(urlopen(url).read())
  5. >>> soup.find(name="span", id="divHi").get_text()
  6. u'33\xb0F'
  7. >>> soup.find(name="span", id="divLo").get_text()
  8. u'28\xb0F'
  9. >>> 
  10.  

Share this Question
Share on Google+
4 Replies


P: 3
There are lots of many websites now that providing a weather information. But one of the best source for that is http://weather.weatherbug.com/ you can visit that site to find what you need.
Dec 22 '14 #2

bvdet
Expert Mod 2.5K+
P: 2,851
The website source can be read with the urllib module and parsed with Beautifulsoup or other suitable HTML parser.
Dec 22 '14 #3

bvdet
Expert Mod 2.5K+
P: 2,851
Using the url suggested by RachelCook and a specific locale, the following will extract the high and low temperatures.
Expand|Select|Wrap|Line Numbers
  1. >>> from urllib import urlopen
  2. >>> from bs4 import BeautifulSoup
  3. >>> url = "http://weather.weatherbug.com/MN/Wahkon-weather.html?zcode=z6286&zip=56386"
  4. >>> soup = BeautifulSoup(urlopen(url).read())
  5. >>> soup.find(name="span", id="divHi").get_text()
  6. u'33\xb0F'
  7. >>> soup.find(name="span", id="divLo").get_text()
  8. u'28\xb0F'
  9. >>> 
  10.  
Dec 22 '14 #4

P: 2
Thank you! That worked perfectly!
Dec 30 '14 #5

Post your reply

Sign in to post your reply or Sign up for a free account.