1

So I'm using Python 3.3 and Beautiful Soup 4, just to get that out there.

What I'm trying to do is create a program that lets me input a word and it searches an online Irish/English and English/Irish dictionary, giving me the results for the word. However, Irish makes use of accented letters. I'm having issues with my code when searching for words that use these letters. All other words work, but when I try to search for an accented one, say "déan", I get

UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 13: ordinal not in range(128)

Here is my code for the Irish section. All I have important before it is asking language and getting the word.

if language == "IRISH" or "I" or "GAEILGE" or "G":
    response = urllib.request.urlopen("http://breis.focloir.ie/en/fgb/"+word)
    html = response.read()
    soup = BeautifulSoup(html) # Gets your soup
    bowl = soup.findAll("div", class_="fgb entry") # Searches for div with correct entry
    for b in bowl:
        print(b.get_text(),"\n")   

I'm pretty sure the error is with the "response" section, but I have no idea how to fix it so it incorporates the word correctly, especially since Python recognizes that "dean" doesn't equal "déan".

Cœur
  • 37,241
  • 25
  • 195
  • 267
davissandefur
  • 161
  • 1
  • 12

0 Answers0