-
Notifications
You must be signed in to change notification settings - Fork 5
/
edgar_scraper.py
31 lines (22 loc) · 1.17 KB
/
edgar_scraper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from sec_cik_mapper import StockMapper
import requests
import json
# for mapping the CIK (aka the primary key/id of every company registered in the SEC)
def edgar_scraper(ticker_name):
# mapper object
cik_mapper = StockMapper()
# ticker_to_cik is a dictionary, just index it by the ticker of the compnay you're interested in,
# e.g.
print(f"{ticker_name}'s cik is {cik_mapper.ticker_to_cik[ticker_name]}")
cik_Value_Of_Ticker = cik_mapper.ticker_to_cik[ticker_name]
cik_Value_Of_Ticker = str(cik_Value_Of_Ticker).zfill(10)
edgar_req_url = f'https://data.sec.gov/submissions/CIK{cik_Value_Of_Ticker}.json'
# if you leave this out, you'll get a 401 response
user_agent_header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"}
edgar_json_response = requests.get(edgar_req_url, headers = user_agent_header).json()
# it's formatted in dict form now
pretty_print = json.dumps(edgar_json_response, indent = 4)
with open(f'{ticker_name}.response.json', 'w') as f:
f.write(pretty_print)
print("If you're seeing this, I executed.")
edgar_scraper("AAPL")