繁体   English   中英

Python-遍历列表

[英]Python - iterate through a list

我正在尝试使用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[] ,但是我无法使其正常工作。 如果您有任何建议,请告诉我。

@FamousJameous给出了正确答案:

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

info['content'][0]['subject']处理了我的数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM