我正在尝试做一些我认为很简单的事情……显然不是。我想使用 python ib api 从 ReportFinSummary 中提取一些数据。我希望能够使用 DPS 数字。我正在尝试用漂亮的汤对 xml 代码进行排序,没有任何乐趣。任何帮助将不胜感激。艾伦
from ib.opt import ibConnection, message
from ib.ext.Contract import Contract
from time import sleep
from bs4 import BeautifulSoup
import pandas as pd
def fundamentalData_handler(msg):
print(msg)
def error_handler(msg):
print(msg)
tws = ibConnection(port=7497, clientId=123)
tws.register(error_handler, message.Error)
tws.register(fundamentalData_handler, message.fundamentalData)
tws.connect()
c = Contract()
c.m_symbol = 'RDSA'
c.m_secType = 'STK'
c.m_exchange = "SMART"
c.m_currency = "GBP"
tws.reqFundamentalData(1,c,'ReportsFinSummary')
soup = BeautifulSoup(tws.reqFundamentalData(1,c,'ReportsFinSummary'),'xml')
DPS_Data = soup.find_all('DividendPerShares')
DPS = []
for dates in DPS_Data:
DPS.append(DPS_Data.get_text())
print(pd.DataFrame({'DPS_Data': DPS}))
sleep(2)
tws.disconnect()