如何解析Omnifocus XML数据以获取有关特定任务的详细信息?

2024-05-19 00:03:48 发布

您现在位置:Python中文网/ 问答频道 /正文

考虑到Omnifocus没有API,我已经创建了一个脚本,用于反复提取XML格式的Omnifocus数据

See linked here for the full omnifocus data set

我正在尽力解析这个数据集,以便能够为一个名为“这是一个测试任务”的任务获取这些属性

我想从这个任务中从xml数据中提取以下属性

  • 任务名称:“这是一个测试任务”
  • 完成日期:2016年2月10日
  • 添加日期:“10/02/2016”
  • 项目:“试验项目”
  • 到期日:2016年11月10日
  • 持续时间:10分钟

下面是我的python脚本:

from bs4 import BeautifulSoup

text_data = BeautifulSoup(xml_data_set)
list_of_tags = s.find_all(tag.has_attr('id')) 
#This creates an array of strings. The string that I'm interested looks like the following: 
#>> e.g. <task id="lyZY7EINc02" op="update"><added>2016-10-02T19:53:09.672Z</added><modified>2016-10-02T19:53:13.912Z</modified><name>This is a test task</name></task>
list_of_dicts = [loads(dumps(xmltodict.parse(str(i)))) for i in l]
#I then use xmltodict to change each tag into an a dictionary. The tag that I'm interested looks like the following: 
#>> e.g. {'task_@id': 'lyZY7EINc02', 'task_modified': '2016-10-02T19:53:13.912Z', 'task_added': '2016-10-02T19:53:09.672Z', 'task_name': 'This is a test task', 'task_@op': 'update'}

虽然,我可以得到任务添加日期和任务名称,但我无法获得我希望获得的其他属性。在


Tags: ofthe数据name脚本idaddedfor
1条回答
网友
1楼 · 发布于 2024-05-19 00:03:48

您只需要使用名称文本来查找节点,然后调用.parent来获取任务节点。在

In [55]: task
Out[55]: <task id="lyZY7EINc02" op="update"><added>2016-10-02T19:53:09.672Z</added><modified>2016-10-02T19:53:13.912Z</modified><name>This is a test task</name></task>

相关问题 更多 >

    热门问题