Python XML Jumpstart in only 5 minutes
HTML-код
- Опубликовано: 1 авг 2024
- Learn how to work with XML in Python in just 5 minutes. This super short demo will get you going quick and not waste your time. You'll see how to use the xml.etree module and ElementTree class to select XML nodes with xpath and convert them to text.
If you want more in-depth Python training, check out my courses at
www.develop.com/training-cour... Наука
Excellent! There are many long-ish ElementTree tuts on YT, but this one gave me just what I needed for a project I'm working on so that I could parse my XML and move on. Thanks a million Mr. K!
Thanks - This video helped me to break through a "writers block" per se of me understanding how to parse XML with python. I was going about it the hard way with a bunch of loops and if statements.
Great video. Amazing what I learned in just 5 minutes! I will be using this weekly. Thanks for the video!
Brilliant! Thank you very much!
Very simple and efficient tutorial ! Hat down to you man !
+Ismail DOUIEB Thanks ;)
Cool. Very quick. And it works great. I'm using Python 2.5. Never knew it came with an XML library.
I was planning on using XML for a game project of mine to store data in a easily modifiable and readable method and this video pretty much summed up all I needed to get started so thank you a lot for putting this video together...helped reduce the headaches a lot
Glad the video was useful!
Awesome instructional video.
Simply the best. Thank you
condolences for your loss, stay strong
outstanding intro on XML, Thanks for sharing.
thanks!
Very helpful video! thank you very much!
Excellent! Thank you!
Thank you for the video, and I am sorry for your loss.
Glad you like it! What about my loss? I don't recall what I mentioned in the video.
excellent video, minimum length, teaching most of the basics of XML parsing. Thanks!
Thank you Adnan.
Thanks for sharing. Nice short introduction
Thanks very much Michael Kennedy
Thanks a lot, Mike, this really helps :-)
thanks, this was very useful.
brilliant, thank you
this is very usefull, Thank you
Loved it!
Thanks Dawn.
Thanks! One thing - at 3:37 you change 'courses/title' to 'course'. I myself have completely missed that which caused me to get back Nonetypes. So for y'all don't overlook that! :) Cheers
How would you print out complete XML as it looks in file ( with same formating )
Nice vid thanks!
Excellent, tks.
Thank you very much kind sir
v helpful..thanks
Thank you
Can you make some more videos about parsing xml files in python? Btw nice job here.
Thanks
nice thanks bruh
Fantastic tutorial for novices like me! May be you can also show how to obtain the xml file from the parent website.
import requests
dom = requests.get("Web Path to the XML file")
Great)
Whenever I try to print the dom it doesn't work, even after importing the XML.etree
How to handel when we have multiple xml file in a directory. Ex. XML Stracture is similar with updated data
Great video. Thanks. I look forward to more XML videos. I have a long xml file that has a root tag that is not named and using info in this video doesn't work. I renamed that tag to root and it works fine. I'm going to dig in to Etree, but wondering how to fix this. Thanks again!
fix this by add getroot() method at dom variable
dom = ElementTree.parse(file_name).getroot()
Wow amazing walk through of data gathering using python! I've been looking for a guide after learning the basics of python and actually applying it to real world example.
Do you have any tips in how to apply programming in python to real world uses? Like browsing and getting data from HTML files or maybe getting data from Craigslist such as item name, price and condition?
Hi Amber, thanks so much. I created a course with 52 tips like these called "Write Pythonic Code Like a Seasoned Developer" training.talkpython.fm/courses/explore_pythonic_code/write-pythonic-code-like-a-seasoned-developer It does cost money but only $39 forever.
Thanks mike! Awesome content, i'm new to python programming and will purchase your python jumpstart course and then move on from there (:
how to convert to dataframe?
Hi Michael,
Element tree is a different way to process XML. DOM is another way. You may mixed them.
s
Awesome stuff, is there any way this could be adjusted to take specific xml lines out of directories containing zipped xmls and write said lines to a csv?
manfan80 Thanks. I suspect so! Use io.path + xml.etree + zipfile at docs.python.org/2/library/zipfile.html to piece it together and write via open() file stream.
Great, will check it out, thanks!
Tell us about the XML parsing, when there is a namespace in file, please
InBackSound Sure, this SO question has a pretty good answer: stackoverflow.com/questions/14853243/parsing-xml-with-namespace-in-python-via-elementtree
Cool. Will it parse variable in memoy or websites response as well as a file?
Sure, it will take a string so you can read the web response or stringify the variable into XML.
after you parse the course title, can you send those titles to the school web server and request for an xml file?
Sure, you can send it wherever you'd like. At that point, it's just Python data structures in memory that are easy to work with.
Hello there, which is better xmltree or bs4 for parsing xml?
XmlTree I would think, if it's well formed XML.
How do you do all that if you have to parse your XML file from an external server and not from your own computer ? Thank you!
Here you go: stackoverflow.com/questions/18308529/python-requests-package-handling-xml-response
@@mikeckennedy I tried that but still not working and is not well explained. I really can't find online anything that works straight forward. I am using Django and trying to extract information from an external XML file on a Template (home - page). I wish it would be in JSON, that would have been a lot easier. Thank you for helping though.
How do you open the XML file so it looks like HTML? Whenever I open the one I'm trying to use, it looks like I opened an image file in a text message. When you do it, it's easy to read.
I think it's just PyCharm. Maybe needs the pro version but I think the community PyCharm also understands HTML/XML.
@@mikeckennedy Thanks! I'll look into it!
What is the name of the IDE that you're using?
it's called pycharm
Yeah but, how did you get the xml file into PyCharm??
I had already downloaded it into a subfolder at the beginning of the video.
What if the XML file does not have the tag? How would you overcome this problem?
I think it always has to have some top level single tag.
@@mikeckennedy Thanks for replying. I actually solved this problem. My client's XML files did not include a tag. So what I did was, I had to replace the first tag in the XML files, and replace it with
And this worked and I was able to process all of the files. Thanks!
@@whichdude420 Perfect!
was reed.xml a semi structured file?
All parsable XML formats are somewhat structured. Some have formal schemas. I don't know if this one did but it did have an implicit structure which is what we used in the xpath queries for elements. You can find it at the URL at 0:28
what is dom...from where that comes from
Document Object Model (DOM): developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction
doesnt work
😀😱😤💩💋🤧🤮
Talks too fast
3:00 There are only two genders!
What are all these bullshit words in Python for? It is like talking to a drunken woman. Besides, it didn't work, of course. And I don't the power anymore to figure out to figure out what I'd had to add to os.path.join.many.many.words.which.are.arbitrarily.made-up.by.a.potsmoker to get the path. Does one have to tell Python everytime on which OS it is running on?