Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
xml to integer
#11
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?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#12
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.
Reply
#13
(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
Reply
#14
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.
Reply
#15
(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)
Reply
#16
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
Reply
#17
It's just pip -V enter,it will return something else for you if it work.
Reply
#18
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?
Reply
#19
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#20
Thanks! Works fine now.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020