PDA

View Full Version : Need help with umlaut in URL


morte0815
2007-01-19, 02:22
Hi,

i try to update my kino.de script at the moment. Now i ran into some problem:

if i want to get cinemadata from citys with no umlaut or special character everythings works well, but if i try to fetch pages from citys with umlaut, i get the wrong page, because the umlauts or special characters are wrong encoded (i think)

so here is the code snipped:


def getPage(self, city, pages):
# city comes from a list of unicode strings!
url = 'http://kino.de/kinosuche.php4?searchortplz='
url = url + urllib.quote(city,'/=&:?')
self.filmContentText.setText(url)
debugwrite(str(url))
pagetext = urllib.urlopen(str(url)).read()
pagetext = pagetext.decode('iso-8859-1')
self.filmContentText.setText(pagetext)
self.HTMLPage = pagetext
if i enter the url in my browser i get the right side:
for example:
München:
http://kino.de/kinosuche.php4?searchortplz=M%FCnchen

but with the urlopen i get the side from
http://kino.de/kinosuche.php4?searchortplz=M%25FCnchen

so in the form on the page is "M%FCnchen" written instead of the wanted "München"


please help!

Tia

Morte

Nuka1195
2007-01-19, 03:34
Don't quote the city.

url = url + city

morte0815
2007-01-19, 11:03
Now i got it working.

Nuka was right with the quoting, but i had to encode the string as latin-1 at the end. so here is the working code (maybe someone runs into the same problem as i did)


def getPage(self, city, pages):
url = 'http://kino.de/kinosuche.php4?searchortplz='
url = url + city
url = url.encode('latin-1')
pagetext = urllib.urlopen(str(url)).read()
pagetext = pagetext.decode('iso-8859-1')
self.filmContentText.setText(pagetext)
self.HTMLPage = pagetext


THX NUKA