---
title: "获取gmail新邮件---python版"
author: "鹤惊昆仑"
date: "2010-07-29T22:57:03Z"
tags: []
categories: ["编程语言"]
slug: "gmail-python"
draft: false
lastmod: "2010-07-29T22:58:46Z"
id: 724844
url: "https://methodmissing.iteye.com/blog/724844"
---

```python

#! /usr/bin/python
# -*- coding: utf-8 -*-
#author newdongyuwei@gmail.com

import httplib2
from xml.dom.minidom import parseString

#https://user:password@mail.google.com/mail/feed/atom
gmail_feed_url = "https://mail.google.com/mail/feed/atom"
user="newdongyuwei"
password = "xxxxxx"

http = httplib2.Http()
http.add_credentials(user, password)#basic auth
resp, content = http.request(gmail_feed_url , "GET", body={}, headers={} )
print resp,content
dom = parseString(content)
feed_list = dom.getElementsByTagName('entry')
result = []
for feed in feed_list:
    result.append(";".join([feed.getelementsbytagname("title")[0].firstChild.nodeValue.strip(),feed.getElementsByTagName("summary")[0].firstChild.nodeValue.strip(),feed.getElementsByTagName("name")[0].firstChild.nodeValue.strip()]))
    
print result

```