Skip to content

Instantly share code, notes, and snippets.

@Kobnar
Last active May 25, 2016 19:14
Show Gist options
  • Select an option

  • Save Kobnar/2619c9f455031464b274d8ed58b8233c to your computer and use it in GitHub Desktop.

Select an option

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
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