Python BS4 with SDMX
<p>I would like to retrieve data given in a SDMX file (like <a href="https://www.bundesbank.de/cae/servlet/StatisticDownload?tsId=BBK01.ST0304&amp;its_fileFormat=sdmx&amp;mode=its" rel="nofollow">https://www.bundesbank.de/cae/servlet/StatisticDownload?tsId=BBK01.ST0304&amp;its_fileFormat=sdmx&amp;mode=its</a>). I tried to use BeautifulSoup, but it seems, it does not see the tags. In the following the code</p>

<pre><code>import urllib2
from bs4 import BeautifulSoup 
url = "https://www.bundesbank.de/cae/servlet/StatisticDownload?tsId=BBK01.ST0304&amp;its_fileFormat=sdmx"
html_source = urllib2.urlopen(url).read()
soup = BeautifulSoup(html_source, 'lxml')
ts_series = soup.findAll("bbk:Series")
</code></pre>

<p>which gives me an empty object.</p>

<p>Is BS4 the wrong tool, or (more likely) what am I doing wrong?
Thanks in advance</p>

<p><code>soup.findAll("bbk:series")</code> would return the result.</p>

<p>In fact, in this case, even you use <code>lxml</code> as the parser, BeautifulSoup still parse it as html, since html tags are case insensetive, BeautifulSoup downcases all the tags, thus <code>soup.findAll("bbk:series")</code> works. See <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#other-parser-problems" rel="nofollow" title="official doc">Other parser problems</a> from the official doc.</p>

<p>If you want to parse it as <code>xml</code>, use <code>soup = BeautifulSoup(html_source, 'xml')</code> instead. It also uses <code>lxml</code> since <code>lxml</code> is the only <code>xml</code> parser BeautifulSoup has. Now you can use <code>ts_series = soup.findAll("Series")</code> to get the result as beautifulSoup will strip the namespace part <code>bbk</code>.</p>

python python-2.7 xml-parsing bs4