【发布时间】:2015-09-01 14:03:26
【问题描述】:
我正在尝试使用 python 并基于Retrieve all contacts from gmail using python 获取 Google 联系人供稿中每个联系人的姓名。
social = request.user.social_auth.get(provider='google-oauth2')
url = 'https://www.google.com/m8/feeds/contacts/default/full' + '?access_token=' + social.tokens + '&max-results=10000'
req = urllib2.Request(url, headers={'User-Agent' : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/11.04 Chromium/12.0.742.112 Chrome/12.0.742.112 Safari/534.30"})
contacts = urllib2.urlopen(req).read()
contacts_xml = etree.fromstring(contacts)
contacts_list = []
n = 0
for entry in contacts_xml.findall('{http://www.w3.org/2005/Atom}entry'):
n = n + 1
for name in entry.findall('{http://schemas.google.com/g/2005}name'):
fullName = name.attrib.get('fullName')
contacts_list.append(fullName)
我能够获得n 的联系人数量,但没有获得fullName 的运气。任何帮助表示赞赏!
【问题讨论】:
标签: python xml google-contacts-api