从 yahoofinancials 下载共同基金最低初始投资

download mutual fund min initial investment from yahoofinancials

我正在尝试下载共同基金的最低初始投资额。我可以在

的雅虎财务上找到它

https://finance.yahoo.com/quote/QALTX/purchase-info?p=QALTX

我尝试使用 yahoofinancials 模块,但它似乎只是 returning get_historical_price_data 的数据。其他扩展似乎只有 return None。有谁知道为什么下面的扩展是 returning None?你也知道我应该使用什么扩展程序来获得最低的初始投资,或者你能建议如何下载它吗?

代码:

import yahoofinancials
from yahoofinancials import YahooFinancials
import pandas as pd

print(YahooFinancials('QALTX').get_key_statistics_data())

输出:

{'QALTX': None}

我刚刚对此进行了测试,您的代码正在为我 return 传输数据。然而,最低初始投资确实 而不是 似乎是我在查看源代码时由该库收集的东西。我可能是错的,但我没找到。

下面的短代码将 return 此特定 URL 的“最低初始投资”,但我不保证此代码适用于其他共同基金。它应该可以工作,但我把它留给其他人来测试。

import decimal as dc
import requests
from bs4 import BeautifulSoup as bs

TICKER = 'QALTX'
URL = 'https://finance.yahoo.com/quote/{}/purchase-info?p={}'.format(TICKER,TICKER)

req = requests.get(URL)

soup = bs(req.text)
# this part is potentially very brittle depending on how often Yahoo Finance changes
elem = soup.select('span[class~="Fl(end)"]')[0]
# replace comma in `10,000` with the empty string
min_initial_investment = dc.Decimal(elem.text.replace(',',''))                                      

输出:

In [90]: min_initial_investment
Out[90]: Decimal('10000')