我正在尝试使用python中的BDS公式提取bloomberg数据,并且我已经下载了pybbg库。我想包括几个覆盖但我收到错误。我正在尝试提取的内容是使用excel API addin:= BDS(“SUBC NO Equity”,“PG_REVENUE”,“PRODUCT_GEO_OVERRIDE = G”,“FUND_PER = Q”= 对于一个覆盖,以下代码有效(https://github.com/kyuni22/pybbg):
import unittest
import datetime
import pybg
class TestPybbg(unittest.TestCase):
def test_bds(self):
tester = pybbg.Pybbg()
data = tester.bds('SUBC NO Equity','PG_REVENUE',overrides={'FUND_PER': 'Q'})
print(data)
if __name__ == '__main__':
unittest.main()
如果公司没有该级别详细信息,则会出现以下错误:
Traceback (most recent call last):
File "C:/Users/bloomberg/.spyder-py3/temp.py", line 23, in test_bds_override
data = tester.bds('AKSO NO Equity','PG_REVENUE',overrides={'PRODUCT_GEO_OVERRIDE':'G','FUND_PER':'Q'})
File "C:\Users\bloomberg\AppData\Local\Continuum\Miniconda3\envs\work\lib\site-packages\pybbg-0.0.1-py3.6.egg\pybbg\pybbg_k.py", line 295, in bds
fieldData = securityData.getValue(i).getElement("fieldData").getElement(field)
File "C:\Users\bloomberg\AppData\Local\Continuum\Miniconda3\envs\work\lib\site-packages\blpapi\element.py", line 347, in getElement
_ExceptionUtil.raiseOnError(res[0])
File "C:\Users\bloomberg\AppData\Local\Continuum\Miniconda3\envs\work\lib\site-packages\blpapi\exception.py", line 145, in raiseOnError
_ExceptionUtil.raiseException(errorCode, description)
File "C:\Users\bloomberg\AppData\Local\Continuum\Miniconda3\envs\work\lib\site-packages\blpapi\exception.py", line 137, in raiseException
raise errorClass(description, errorCode)
blpapi.exception.NotFoundException: Attempt to access unavailable sub-element 'PG_REVENUE' of element 'fieldData'. (0x0006000d)
答案 0 :(得分:0)
我想通了,如果你在公式中添加以下内容,你可以包含几个覆盖:
def parse(u):
u = u.rstrip('\n')
r = requests.get(u, headers=headers)
if r.status_code == 200:
html = r.text.strip()
soup = BeautifulSoup(html, 'lxml')
headings = soup.select('table p')
for h in headings:
b = h.find('b')
if b is not None:
print(b.text)
print(h.text + '\n')
print('=================================')
url = 'http://www.nndb.com/people/742/000024670/'