Python and Beautiful soup - getting values and saving them in a text file
Question: I have sort of a XML file contains many records of relevant info that looks
like this

    
    
    <file>
    <record>
    <type>a</type>
    <number>2</number>
    </record>
    
    <record>
    <type>b</type>
    <number>9</number>
    </record>
    

etc.

I want BS to read all the XML file and to give me the results by columns :

a 2

b 9 etc

EDIT

Thank you all for pitching in. I installed xml parser and I'm using bs4 xml
mode. I don't get the error anymore however I get :

a b

2 9

instead of

a 2

b 9

New code :

    
    
    from bs4 import BeautifulSoup
    soup = BeautifulSoup(open('file.xml'),"xml")
    
    with open('output.txt') as f: 
       for type1,number in (soup.findall('type'),soup.findall('number')):
         f.write ('%s\t%s\n' % (type1.text, number.text))
    

2nd EDIT :

If I add a 3rd record in the XML file, I get the following error

Traceback (most recent call last): File "multixmlsript.py", line 8, in for
type1,number in (soup.findAll('type'),soup.findAll('number')): ValueError: too
many values to unpack


Answer: 
    from BeautifulSoup import BeautifulStoneSoup
    
    soup = BeautifulStoneSoup(open('path/to/file'))
    
    with open('/path/to/output.txt', 'w') as f:
        for i in range(len(soup.findAll('type'))):
            f.write ('%s\t%s\n' % (soup.findAll('type')[i].text, soup.findAll('number')[i].text))
    

You have used the `BeautifulSoup` it is for HTML. But you need to use
`BeautifulStoneSoup` for xml. I hope this will be help you.

