我正在尝试重新学习python,所以我的技能很欠缺。我现在正在玩PubMedAPI。我试图解析给定的here的XML文件,然后运行一个循环遍历每个子文件('/pubmedarticle')并获取一些内容,现在只是文章标题,并将它们输入到pubmedid(pmid)键下的字典中。在
即输出应如下所示:
{'29150897': {'title': 'Determining best outcomes from community-acquired pneumonia and how to achieve them.'}
'29149862': {'title': 'Telemedicine as an effective intervention to improve antibiotic appropriateness prescription and to reduce costs in pediatrics.'}}
稍后我将添加更多的因素,如作者和期刊等,现在我只想知道如何使用lxml包将我想要的数据放入字典中。我知道有很多软件包可以帮我做到这一点,但这违背了学习的目的。我尝试了很多不同的方法,这就是我目前要做的:
^{pr2}$我可能对如何进行这一过程有误解,但如果有人能提供见解或引导我朝正确的方向获取资源,我将不胜感激。在
编辑:我很抱歉。我写这篇文章比我应该写得快得多。所有的案子我都办好了。此外,它抛出的结果似乎结合了PMID,同时给出了第一个标题:
{'2725403628806902': {'title': 'Handshake Stewardship: A Highly Effective Rounding-based Antimicrobial Optimization Service.Monitoring, documenting and reporting the quality of antibiotic use in the Netherlands: a pilot study to establish a national antimicrobial stewardship registry.'}}
助教
代码.py:
注意事项:
输出:
首先,xml是case-sensitive,在xpath中使用小写标记。在
另外,我认为
pmid
应该是某个数字(或代表数字的字符串),在您的例子中,这似乎是不同的:在我的测试中
生成串联数字的字符串,这不是您要查找的。在
相关问题 更多 >
编程相关推荐