Reputation: 2024
I want to get the elements from a XML that can be fetched from a URL.
I have written the following code
import xml.etree.ElementTree as ET
url = 'https://www.sec.gov/Archives/edgar/data/1568219/000156821918000001/primary_doc.xml'
req = ulib.Request(url)
primaryXML = ulib.urlopen(req)
xmlData = primaryXML.read()
content = ET.fromstring(xmlData)
The XML that is available is
<edgarSubmission xmlns="http://www.sec.gov/edgar/thirteenffiler" xmlns:com="http://www.sec.gov/edgar/common">
<headerData>
<submissionType>13F-HR</submissionType>
<filerInfo>
<liveTestFlag>LIVE</liveTestFlag>
<flags>
<confirmingCopyFlag>false</confirmingCopyFlag>
<returnCopyFlag>false</returnCopyFlag>
<overrideInternetFlag>false</overrideInternetFlag>
</flags>
<filer>
<credentials>
<cik>0001568219</cik>
<ccc>XXXXXXXX</ccc>
</credentials>
</filer>
<periodOfReport>12-31-2017</periodOfReport>
</filerInfo>
</headerData>
<formData>
<coverPage>
<reportCalendarOrQuarter>12-31-2017</reportCalendarOrQuarter>
<filingManager>
<name>TD Ameritrade Trust Co</name>
<address>
<com:street1>PO BOX 17748</com:street1>
<com:city>DENVER</com:city>
<com:stateOrCountry>CO</com:stateOrCountry>
<com:zipCode>80217-0748</com:zipCode>
</address>
</filingManager>
<reportType>13F HOLDINGS REPORT</reportType>
<form13FFileNumber>028-15163</form13FFileNumber>
<provideInfoForInstruction5>N</provideInfoForInstruction5>
</coverPage>
<signatureBlock>
<name>Erik Hunt</name>
<title>Senior Analyst</title>
<phone>303-294-5311</phone>
<signature>Erik Hunt</signature>
<city>Denver</city>
<stateOrCountry>CO</stateOrCountry>
<signatureDate>02-26-2018</signatureDate>
</signatureBlock>
<summaryPage>
<otherIncludedManagersCount>0</otherIncludedManagersCount>
<tableEntryTotal>20</tableEntryTotal>
<tableValueTotal>268468</tableValueTotal>
<isConfidentialOmitted>false</isConfidentialOmitted>
</summaryPage>
</formData>
</edgarSubmission>
I want to get the value of submissionType
When I try
content.find("edgarSubmission/headerData/submissionType")
I dont get any result. I want to get 13F-HR
Can someone please explain what I am doing wrong ?
Upvotes: 0
Views: 194
Reputation: 22440
Try this. If 13F-HR
is your only requirement to fetch, the script should do that.
import requests
from lxml.html import fromstring
res = requests.get("https://www.sec.gov/Archives/edgar/data/1568219/000156821918000001/primary_doc.xml")
tree = fromstring(res.content)
item = tree.cssselect("submissionType")[0].text
print(item)
OR
from urllib.request import urlopen
from lxml.html import fromstring
res = urlopen("https://www.sec.gov/Archives/edgar/data/1568219/000156821918000001/primary_doc.xml")
tree = fromstring(res.read())
item = tree.cssselect("submissionType")[0].text
print(item)
Output:
13F-HR
Upvotes: 2