Python - 遍历列表

时间:2017-12-08 17:00:36

标签: python

我正在尝试使用python自动化电子邮件报告。我的问题是我无法从我的电子邮件客户端输出的数据中提取subject

缩写数据集:

[(messageObject){
   id = "0bd503eb00000000000000000000000d0f67"
   name = "11.26.17 AM [TXT-CAT]{Shoppers:2}"
   status = "active"
   messageFolderId = "0bd503ef0000000000000000000000007296"
   content[] = 
      (messageContentObject){
         type = "html"
         subject = "Early Cyber Monday – 60% Off Sitewide "
         }
         }
         ]

我可以像这样拉其他字段:

messageId = []
messageName = []
subject = []

for info in messages:
    messageId.append(str(info['id']))
    messageName.append(str(info['name']))
    subject.append(str(info[content['subject']]))

data = pd.DataFrame({
    'id': messageId,
    'name': messageName,
    'subject': subject
}) 
data.head()

我一直试图使用for循环迭代content[],但我无法让它工作。如果您有任何建议,请告诉我。

1 个答案:

答案 0 :(得分:0)

@FamousJameous给出了正确答案:

该格式称为SOAP。我对语法的猜测是info['content']['subject']info['content'][0]['subject']

info['content'][0]['subject']使用了我的数据。