import os
import requests
reply = requests.get("https://www.sec.gov/Archives/edgar/full-index/2026/QTR1/master.idx", headers={"User-Agent": os.environ["SEC_USER_AGENT"]}, timeout=30)
reply.raise_for_status()
index_bytes = reply.contentHow do I read one SEC filing’s index, XML and HTML?
After this lesson, you can find an initial Schedule 13D in the SEC’s EDGAR index, read when the ownership event happened, and extract the purchases listed in its exhibit.
How do I find the initial filing in the index?
Each data line of EDGAR’s quarterly master index holds five fields separated by |, the company’s CIK identifier, its name, the form, the filing date and the file name, so line.split("|") turns each line into a row. Selecting the form "SCHEDULE 13D" picks AAA’s original filing of 4 March and leaves out its amendment, "SCHEDULE 13D/A", of 6 March.
AAA is a made-up company, and BBB and CCC report stakes in it, with two made-up index lines in place of a download. A live request needs your name and email in the User-Agent header, here read from the environment variable SEC_USER_AGENT. .item() reads the single selected value and raises an error if the selection holds more or fewer. The Schedule 13D tutorial applies these steps to a full quarter.
The following box, which does not run on this page, downloads the index of the first quarter of 2026.
The following box turns the two index lines into a table and selects the original filing.
import pandas as pd
lines = [
"100001|AAA|SCHEDULE 13D|2026-03-04|edgar/data/100001/0000100002-26-000001.txt",
"100001|AAA|SCHEDULE 13D/A|2026-03-06|edgar/data/100001/0000100002-26-000002.txt",
]
index = pd.DataFrame([line.split("|") for line in lines], columns=["CIK", "Company", "Form", "Filed", "Filename"])
print(index[["Form", "Filed"]])
filed = index.loc[index["Form"] == "SCHEDULE 13D", "Filed"].item()
print(filed) Form Filed
0 SCHEDULE 13D 2026-03-04
1 SCHEDULE 13D/A 2026-03-06
2026-03-04
How do I read the event date and the owners from the XML?
root.findtext(".//s:dateOfEvent", namespaces=ns) returns the text of the first dateOfEvent tag, the day of the ownership event, 2 March, two days before the filing, and pd.read_xml(..., xpath=".//s:reportingPersonInfo") returns one row per reporting owner, BBB with 6.5% of AAA’s shares and CCC with 5.5%.
An XML tag names a field, and the xmlns address puts all tags in the SEC’s namespace, so a search names the namespace through a prefix, here s. ET.fromstring reads the text into a tree, and .// searches the whole tree. io.StringIO(xml) gives pandas the text as a file. A study of the event uses the event date, and a strategy can use the filing only after it became public.
The following box reads the event date and the owners.
import xml.etree.ElementTree as ET
from io import StringIO
xml = """<edgarSubmission xmlns="http://www.sec.gov/edgar/schedule13D">
<formData>
<coverPageHeader><dateOfEvent>03/02/2026</dateOfEvent><issuerInfo><issuerName>AAA</issuerName></issuerInfo></coverPageHeader>
<reportingPersons>
<reportingPersonInfo><reportingPersonName>BBB</reportingPersonName><percentOfClass>6.5</percentOfClass></reportingPersonInfo>
<reportingPersonInfo><reportingPersonName>CCC</reportingPersonName><percentOfClass>5.5</percentOfClass></reportingPersonInfo>
</reportingPersons>
</formData>
</edgarSubmission>"""
ns = {"s": "http://www.sec.gov/edgar/schedule13D"}
root = ET.fromstring(xml)
print(root.findtext(".//s:dateOfEvent", namespaces=ns), filed)
owners = pd.read_xml(StringIO(xml), xpath=".//s:reportingPersonInfo", namespaces=ns)
print(owners)03/02/2026 2026-03-04
reportingPersonName percentOfClass
0 BBB 6.5
1 CCC 5.5
How do I read a table from an HTML exhibit?
pd.read_html(StringIO(html), flavor="lxml") returns a list of every table in the HTML, and [0] takes the first, here BBB’s two purchases of AAA, 80 shares on 2 March and 120 on 3 March.
In HTML, table encloses a table, tr starts a row, th marks a heading and td a data cell. An exhibit with several tables needs a check of the headings before a table is taken by position.
The following box reads the exhibit’s table.
html = """<table>
<tr><th>Date</th><th>Shares</th></tr>
<tr><td>2026-03-02</td><td>80</td></tr>
<tr><td>2026-03-03</td><td>120</td></tr>
</table>"""
print(pd.read_html(StringIO(html), flavor="lxml")[0]) Date Shares
0 2026-03-02 80
1 2026-03-03 120
Your turn
Print the owners with more than 6% of AAA’s shares. You should see BBB with 6.5.
The mask compares each owner’s percentage with 6.
print(owners[owners["percentOfClass"] > 6]) reportingPersonName percentOfClass
0 BBB 6.5