Answers:
Quant SE是获取财务数据相关问题的最佳场所:
该网站列出了过去10年中标普100和纳斯达克100公司的历史市值和企业价值。您可以将数据集导出到Excel。
http://marketcapitalizations.com/historical-data/historical-data-categories/valuations/
您也可以尝试与他们联系以获取较长时间的数据。
我会这样做。
import requests
from bs4 import BeautifulSoup
base_url = 'https://finviz.com/screener.ashx?v=152&s=ta_topgainers&o=price&c=1,2,6,7,25,65,67'
html = requests.get(base_url)
soup = BeautifulSoup(html.content, "html.parser")
main_div = soup.find('div', attrs = {'id':'screener-content'})
light_rows = main_div.find_all('tr', class_="table-light-row-cp")
dark_rows = main_div.find_all('tr', class_="table-dark-row-cp")
data = []
for rows_set in (light_rows, dark_rows):
for row in rows_set:
row_data = []
for cell in row.find_all('td'):
val = cell.a.get_text()
row_data.append(val)
data.append(row_data)
# sort rows to maintain original order
data.sort(key=lambda x: int(x[0]))
import pandas
pandas.DataFrame(data).to_csv("AAA.csv", header=False)