Last active
May 25, 2016 19:14
-
-
Save Kobnar/2619c9f455031464b274d8ed58b8233c to your computer and use it in GitHub Desktop.
A simple function using Requests and BeautifulSoup to retrieve a market security's CIK number from the SEC web portal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import bs4 | |
| _CIK_URI = 'http://www.sec.gov/cgi-bin/browse-edgar' \ | |
| '?action=getcompany&CIK={s}&count=10&output=xml' | |
| def get_cik(symbol): | |
| """ | |
| Retrieves the CIK identifier of a given security from the SEC based on that | |
| security's market symbol (i.e. "stock ticker"). | |
| :param symbol: Unique trading symbol (e.g. 'NVDA') | |
| :return: A corresponding CIK identifier (e.g. '1045810') | |
| """ | |
| response = requests.get(_CIK_API_URI.format(s=symbol)) | |
| page_data = bs4.BeautifulSoup(response.text, "html.parser") | |
| cik = page_data.companyinfo.cik.string | |
| return cik | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment