Show forecast using Yahoo! Weather

Note: This snippet uses piksemel module to parse XML files. If you don’t have it, read this article to install it.

First of all, you need the WOEID (Where on Earth Identification) of the city. In order to learn it, go to and search for the city. You’ll find the WOEID at the end of the url of the page.

# for Istanbul, TR
woeid = 2344116

Use this id in Yahoo! Weather API url, for w parameter.

weatherUri = "" % woeid

If you want the results to be in metric units, add u=c parameter into your query.

weatherUri = "" % woeid

Using urllib, fetch the XML file:

import urllib

xml = urllib.urlopen(weatherUri).read()

We can parse this XML easily using piksemel:

import piksemel

temp = piksemel.parseString(xml).getTag('channel').getTag('item').getTag('yweather:condition').getAttribute('temp')

You can also view XML file and look for other resources such as: humidity, visibility, wind, etc.

How to install piksemel module

piksemel is a easy to use python XML parser, based on iksemel.

Not: If you’re using Pardus, piksemel is preinstalled on your system.

Not: If you’re using Windows, before you continue make sure you’ve already installed mingw32 to your system and its directory is included in PATH.

Steps for Linux users:

  • Download the package from and unpack it.
  • Run:
    python build
  • Run:
    python install

Steps for Windows users:

  • Download the package from and unpack it.
  • In piksemel-1.3.1 directory, run: bdist_wininst build --compiler=mingw32
  • Run the installer file under the piksemel-1.3.1/dist directory.