The following Python code uses BeautifulStoneSoup to obtain information on the LibraryThing API for Tolkien "The Children of Húrin".
import urllib2 from BeautifulSoup import BeautifulStoneSoup URL = ("http://www.librarything.com/services/rest/1.0/" "?method=librarything.ck.getwork&id=1907912" "&apikey=2a2e596b887f554db2bbbf3b07ff812a") soup = BeautifulStoneSoup(urllib2.urlopen(URL), convertEntities=BeautifulStoneSoup.ALL_ENTITIES) title_field = soup.find('field', attrs={'name': 'canonicaltitle'}) print title_field.find('fact').string
Unfortunately, instead of “Húrin,” he types “Húrin.” This is obviously an encoding problem, but I can't decide what I need to do to get the expected result. Help would be greatly appreciated.
source share