I need to use METAR weather information in a python script. I found http://pypi.python.org/pypi/metar/1.4.0 which seems like it should work for what I need for current METARs. However, I also need to use archived weather information.
I found Navlost.eu, which seems to work well for what I need. For example,
http://www.navlost.eu/aero/metar/?icao=KBOS&dt0=2010-07-14+02%3A00%3A00&c=1&rt=metar
The python METAR module accesses a text file and parses that. How do I parse this webpage in a similar manner so that I am only grabbing the “KBOS 140154Z 15006KT 8SM -RA OVC034 23/22 A2994” text in this example?
Looking at the raw
HTMLreturned by the above link, you can see the METAR data nested between<code>tags:So use a Python regular expression to get at it:
The regular expression is found on the
re.compileline, and the(.*)means that you’re interested in all characters between the parentheses. The functionr.findallreturns all strings that match the expression, and[0]just gives the first one.The following is the output: