Facebook图形API编码-Python

Facebook图形API编码-Python,python,facebook-graph-api,Python,Facebook Graph Api,我在兜圈子,尝试了很多不同的方法,所以我想我的核心理解是错误的。如果能帮助我理解编码/解码问题,我将不胜感激 import urllib2 result = urllib2.urlopen("https://graph.facebook.com/163146530455639") rawdata = result.read().decode('utf-8') print "HEADER: " + str(result.info()) print "I want this to work "

我在兜圈子,尝试了很多不同的方法,所以我想我的核心理解是错误的。如果能帮助我理解编码/解码问题,我将不胜感激

import urllib2

result = urllib2.urlopen("https://graph.facebook.com/163146530455639")
rawdata = result.read().decode('utf-8')

print "HEADER: " + str(result.info())

print "I want this to work ", rawdata.find('http://www.facebook.com')
print "I dont want this to work ", rawdata.find('http:\/\/www.facebook.com')
我猜我得到的不是utf-8,尽管标题似乎说是。或者作为Python的新手,我在做一些愚蠢的事情(

谢谢你的帮助


Phil

您将从Facebook获得JSON,因此最简单的方法是使用内置的
JSON
模块对其进行解码(如果您使用的是Python 2.6+,否则必须安装)

给你:

u'http://www.facebook.com/GrosvenorCafe'
我确实尝试过:chardet.detect(rawdata){'confidence':1.0,'encoding':'ascii'}
u'http://www.facebook.com/GrosvenorCafe'