import httplib2
import urllib
import re
import os
class forismatic:
def __init__(self, language):
self.language=language
self.quote=''
self.author=''
self.quoteLink=''
def getQuote(self):
http=httplib2.Http()
url='http://api.forismatic.com/api/1.0/'
body={'method':'getQuote', 'key':'', 'format':'xml', 'lang':self.language}
headers={'Content-type':'application/x-www-form-urlencoded'}
self.response=http.request(url, 'POST', headers=headers, body=urllib.urlencode(body))
self.parse()
def parse(self):
resp=str(self.response)
temp=re.findall(r'<quoteText>(.*?)</quoteText>', resp)
self.quote=temp[0]
temp=re.findall(r'<quoteAuthor>(.*?)</quoteAuthor>', resp)
self.author=temp[0]
temp=re.findall(r'<quoteLink>(.*?)</quoteLink>', resp)
self.quoteLink=temp[0]
from api import forismatic
m=forismatic('ru')
m.getQuote()
print m.quote
Кажется видится в чём проблема. В данном случае переменная “а” - как раз мой m.quote
>>> a
'\\xd0\\x96\\xd0\\xb8\\xd0\\xb7\\xd0\\xbd\\xd1\\x8c \\xd0\\xba\\xd0\\xbe\\xd1\\x80\\xd0\\xbe\\xd1\\x82\\xd0\\xba\\xd0\\xb0, \\xd0\\xb8 \\xd0\\xbf\\xd0\\xbe\\xd1\\x8d\\xd1\\x82\\xd0\\xbe\\xd0\\xbc\\xd1\\x83 \\xd0\\xbd\\xd0\\xb5 \\xd1\\x81\\xd0\\xbb\\xd0\\xb5\\xd0\\xb4\\xd1\\x83\\xd0\\xb5\\xd1\\x82 \\xd1\\x82\\xd0\\xb5\\xd1\\x80\\xd1\\x8f\\xd1\\x82\\xd1\\x8c \\xd0\\xb2\\xd1\\x80\\xd0\\xb5\\xd0\\xbc\\xd0\\xb5\\xd0\\xbd\\xd0\\xb8, \\xd0\\xbd\\xd1\\x83\\xd0\\xb6\\xd0\\xbd\\xd0\\xbe \\xd0\\xbd\\xd0\\xb0\\xd1\\x81\\xd0\\xbb\\xd0\\xb0\\xd0\\xb6\\xd0\\xb4\\xd0\\xb0\\xd1\\x82\\xd1\\x8c\\xd1\\x81\\xd1\\x8f \\xd0\\xb5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