@erlend I'd use the mechanism browsers do: grab the webpage, possibly preferably the top page, and look for a meta rel='icon' tag. Might also consider meta rel='apple-touch-icon', depending on your context; sometimes, these are available at higher resolutions (but sometimes, they follow slightly different design constraints).