0

I need some help in parsing some XML which I am retrieving via an HTTP address like this:

response = requests.get(url)

I've read a lot of posts where people say to convert it into a dictionary, so I tried this:

d = xmltodict.parse(response.content)

But I'm not having any real luck. The XML is basically some market data, like this:

<INFOTECXML xmlns="http://0.0.0.0/XML/" xmlns:xsi="some address" xsi:schemaLocation="http://192.168.1.1/XML/ http://192.168.1.1/XML/Schemas/infotec.xsd">
  <QUOTELIST nbsymbols="544" avail-quot="49453">
    <q symbol="BIDU220422C60.P" status="Ok">
      <put_call>C</put_call>
      <expiry>2022-04-22</expiry>
      <strike>60</strike>
      <last src="pclose">86.65</last>
      <time>15:00:01</time>
      <open/>
      <high/>
      <low/>
      <netchg src="PNetchg">2.15</netchg>
      <volume/>
      <bid>85.5</bid>
      <ask>89.7</ask>
      <pclose>86.65</pclose>
      <volatility/>
      <imvollast/>
      <thval>87.7077</thval>
      <exercise>A</exercise>
      <openint>0</openint>
    </q>
    <q symbol="BIDU220429C60.P" status="Ok">
      <put_call>C</put_call>
      <expiry>2022-04-29</expiry>
      <strike>60</strike>
      <last src="pclose">86</last>
      <time>15:00:02</time>
      <open/>
      <high/>
      <low/>
      <netchg src="PNetchg">1.4</netchg>
      <volume/>
      <bid>85.5</bid>
      <ask>89.95</ask>
      <pclose>86</pclose>
      <volatility/>
      <imvollast/>
      <thval>87.7129</thval>
      <exercise>A</exercise>
      <openint>0</openint>
    </q>
  </QUOTELIST>
</INFOTECXML>

The actual XML is much larger than just the 2 items, there could be as many as 1000. So, once I retrieve that data via the "requests" method, what is my best way to process it, and access the different tags? Convert it to a dictionary? Write it to a file? is this indexed in any way? I'm pretty new at this, so, I need a little directional help.

Many thanks!

Landon Statis
  • 573
  • 1
  • 7
  • 18

0 Answers0