使用python读取xbrl [英] Reading xbrl with python

查看:447
本文介绍了使用python读取xbrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在xbrl文件中找到特定的标签.我最初尝试使用python-xbrl软件包,但这并不是我想要的,因此我的代码基于该软件包中提供的代码.

I am trying find particular tag in an xbrl file. I originally tried using python-xbrl package, but it is not exactly what I want, so I based my code on the one available from the package.

这是我感兴趣的xbrl部分

Here's the part of xbrl that I am interested in

<us-gaap:LiabilitiesCurrent contextRef="eol_PE2035----1510-Q0008_STD_0_20150627_0" unitRef="iso4217_USD" decimals="-6" id="id_5025426_6FEF05CB-B19C-4D84-AAF1-79B431731049_1_24">65285000000</us-gaap:LiabilitiesCurrent>
<us-gaap:Liabilities contextRef="eol_PE2035----1510-Q0008_STD_0_20150627_0" unitRef="iso4217_USD" decimals="-6" id="id_5025426_6FEF05CB-B19C-4D84-AAF1-79B431731049_1_28">147474000000</us-gaap:Liabilities>

这是代码

python-xbrl程序包基于beautifulsoup4和其他几个程序包.

python-xbrl package is based on beautifulsoup4 and several other packages.

liabilities = xbrl.find_all(name=re.compile("(us-gaap:Liabilities)",
                          re.IGNORECASE | re.MULTILINE))

我得到us-gaap:LiabilitiesCurrent的值,但是我想得到us-gaap:Liabilities的值. 现在,一旦找到匹配项,就将其存储.但是在很多情况下,由于xbrl中的标签格式,其匹配不正确.我相信我需要更改re.compile()部分以使其正常工作.

I get the value for us-gaap:LiabilitiesCurrent, but I want value for us-gaap:Liabilities. Right now as soon as it finds a match it, stores it. But in many cases its the wrong match due to the tag format in xbrl. I believe I need to change re.compile() part to make it work correctly.

推荐答案

请尝试在其末尾添加$美元符号,以表明该美元符号后的其他字符均不匹配:

Try it with a $ dollar sign at the end to indicate not to match anything else following the dollar sign:

liabilities = xbrl.find_all(name=re.compile("(us-gaap:Liabilities$)",
                          re.IGNORECASE | re.MULTILINE))

这篇关于使用python读取xbrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆