Parsing XML from websites and save the code?
<p>I would like to parse the xml code from a website like 
<a href="http://ops.epo.org/3.1/rest-services/published-data/publication/docdb/EP1000000/biblio" rel="nofollow">http://ops.epo.org/3.1/rest-services/published-data/publication/docdb/EP1000000/biblio</a>
and save it in another xml or csv file.</p>

<p>I tried it with this:</p>

<pre><code>import urllib.request 
web_data = urllib.request.urlopen("http://ops.epo.org/3.1/rest-services/published-data/publication/docdb/EP1000000/biblio")
str_data = web_data.read()
try:
   f = open("file.xml", "w")
   f.write(str(str_data))
   print("SUCCESS")
except:
   print("ERROR")
</code></pre>

<p>But in the saved XML data is between every element '\n' and at the beginning ' b' '</p>

<p>How can i save the XML data without all the 'n\' and ' b' '?</p>

<p>If you write the xml file in binary mode, you don't need to convert the data read into a string of characters first. Also, if you process the data a line at a time, that should get rid of <code>'\n'</code> problem. The logic of your code could also be structured a little better IMO, as shown below:</p>

<pre><code>import urllib.request

web_data = urllib.request.urlopen("http://ops.epo.org/3.1/rest-services"
                                  "/published-data/publication"
                                  "/docdb/EP1000000/biblio")
data = web_data.read()
with open("file.xml", "wb") as f:
    for line in data:
        try:
            f.write(data)
        except Exception as exc:
            print('ERROR')
            print(str(exc))
            break
    else:
        print('SUCCESS')
</code></pre>

python xml python-3.5