【问题标题】:Parsing Google contacts feed in Python在 Python 中解析 Google 联系人提要
【发布时间】: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


    【解决方案1】:

    如果有人需要,我找到了从 Google 联系人提要中获取姓名的解决方案:

    for entry in contacts_xml.findall('{http://www.w3.org/2005/Atom}entry'):
        for title in entry.findall('{http://www.w3.org/2005/Atom}title'):
            name = title.text
            contacts_list.append(name)
    

    【讨论】:

      猜你喜欢
      • 2011-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多