File size: 742 Bytes
9df4cc0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import json
import requests
import pandas as pd
from tqdm.notebook import tqdm

df = pd.read_csv("NAS.csv", index_col=0)
stock_list = df.index.to_list()

api_key = YOUR_API_KEY  # You may find your api key here https://site.financialmodelingprep.com/developer/docs/api-keys

all = pd.DataFrame()
for stock in tqdm(stock_list):
    for page in tqdm(range(500)):
        url = f"https://financialmodelingprep.com/api/v3/stock_news?tickers={stock}&page={page+1}&apikey={api_key}"
        res = requests.get(url)
        res = json.loads(res.text)
        if len(res) == 0:
            break
        else:
            res = pd.DataFrame(res)
            all = pd.concat([all, res])

all = all.reset_index(drop=True)
all.to_csv("dataset_more.csv")