Python Forum

Full Version: xml to integer
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Hm!
When you tell us that you get an error, how can we help without knowing what is that error?
It works for me, so how can you get an error?
I tried this and get error that it can't find tmp/test.xml file:
from bs4 import BeautifulSoup

open('/tmp/test.xml', 'r') 
xml_data = xml_file.read()
     

soup = BeautifulSoup(xml_data, 'lxml')

print(soup.gps.latitude.text)

Thanks snippsat - works fine.
(Apr-25-2017, 05:27 PM)kendias Wrote: [ -> ]I tried this and get error that it can't find tmp/test.xml file:
Is test.xml in tmp folder?
You have not copy code right from wavic post post.
with open('/tmp/test.xml', 'r') as xml_file:
    xml_data = xml_file.read()

soup = BeautifulSoup(xml_data, 'lxml')
print(soup.gps.latitude.text)
Here you also need to install lxml pip install lxml
Thanks, initially copied verbatim from Wavic did not work hence changed it.
Not clear on test.xml i.e. where can I find it or is it a file I create myself?
Also link to d'load & install lxml.
(Apr-25-2017, 08:03 PM)kendias Wrote: [ -> ]Not clear on test.xml i.e. where can I find it or is it a file I create myself?
You most of course make the file or point to the file with your XML data.
Quote:Also link to d'load & install lxml
lxml
pip is Python install tool,it dos all automatic download and install.
Check in Terminal or cmd(Windows) that is work. 
Eg:
$ pip -V
pip 9.0.1 from /home/mint/new_age/lib/python3.5/site-packages (python 3.5)
Tried pip -V, then pip 9.0.1 from /home/mint/new_age/lib/python3.5/site-packages (python 3.5); get error msg on 9.0.1, just will not take it.
Entered these commands in the cmdline
It's just pip -V enter,it will return something else for you if it work.
Thanks. Did pip -V and got "pip 1.5.6 from /usr/lib/python2.7/dist-packages (python 2.7)". From what you said this is OK. Now what about lxml - has to be installed?
Hello!
You should look at the code, not just blindly copy/paste it.  Smile
'tmp/test.xml' is 'test.xml' file which I created from the xml snippet that you have provided. And its location is in the tmp/ directory. But this is on my computer. The path and the file name on yours could be different.

(Apr-25-2017, 11:34 PM)kendias Wrote: [ -> ]Now what about lxml - has to be installed?
Yes. The command to do it is: pip install lxml
As @snippsat already noticed
Thanks! Works fine now.
Pages: 1 2 3