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...
  • НаукаНаука

Комментарии • 89

  • @dandavis8500
    @dandavis8500 3 года назад +1

    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!

  • @RayMillTN1
    @RayMillTN1 8 лет назад +3

    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.

  • @julianaguirre5732
    @julianaguirre5732 Год назад +1

    Great video. Amazing what I learned in just 5 minutes! I will be using this weekly. Thanks for the video!

  • @IlanPerez
    @IlanPerez 8 лет назад +2

    Brilliant! Thank you very much!

  • @Atlas-ck9vm
    @Atlas-ck9vm 8 лет назад +3

    Very simple and efficient tutorial ! Hat down to you man !

  • @SHONNER
    @SHONNER 7 лет назад

    Cool. Very quick. And it works great. I'm using Python 2.5. Never knew it came with an XML library.

  • @NeoTrggrTheGammer
    @NeoTrggrTheGammer 3 года назад

    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

  • @Thankful_n_Grateful
    @Thankful_n_Grateful 8 лет назад +3

    Awesome instructional video.

  • @aitools111
    @aitools111 6 лет назад

    Simply the best. Thank you

  • @user-pd1en1fd1r
    @user-pd1en1fd1r 4 года назад +1

    condolences for your loss, stay strong

  • @mahyarazad
    @mahyarazad 4 года назад +2

    outstanding intro on XML, Thanks for sharing.

  • @PrinceN00B
    @PrinceN00B 3 года назад +1

    Very helpful video! thank you very much!

  • @nicholasberglund
    @nicholasberglund 3 года назад

    Excellent! Thank you!

  • @gorbo1489
    @gorbo1489 5 лет назад

    Thank you for the video, and I am sorry for your loss.

    • @mikeckennedy
      @mikeckennedy  5 лет назад

      Glad you like it! What about my loss? I don't recall what I mentioned in the video.

  • @m.adnankhan8245
    @m.adnankhan8245 2 года назад +1

    excellent video, minimum length, teaching most of the basics of XML parsing. Thanks!

  • @jasonzhang6534
    @jasonzhang6534 3 года назад

    Thanks for sharing. Nice short introduction

  • @EgidioSuriano
    @EgidioSuriano 8 лет назад

    Thanks very much Michael Kennedy

  • @satsel2k
    @satsel2k 4 года назад

    Thanks a lot, Mike, this really helps :-)

  • @wolftribe66
    @wolftribe66 7 лет назад

    thanks, this was very useful.

  • @R2D2022
    @R2D2022 3 года назад

    brilliant, thank you

  • @wajdibelhajsalem2700
    @wajdibelhajsalem2700 3 года назад

    this is very usefull, Thank you

  • @MLDawn
    @MLDawn 2 года назад +1

    Loved it!

  • @pilgrim2510
    @pilgrim2510 5 лет назад +5

    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

  • @Thankful_n_Grateful
    @Thankful_n_Grateful 8 лет назад

    How would you print out complete XML as it looks in file ( with same formating )

  • @BrendanMetcalfe
    @BrendanMetcalfe 4 года назад +1

    Nice vid thanks!

  • @frclasso
    @frclasso 5 лет назад

    Excellent, tks.

  • @thetruereality2
    @thetruereality2 3 года назад +1

    Thank you very much kind sir

  • @RS-el7iu
    @RS-el7iu 3 года назад

    v helpful..thanks

  • @illumeo
    @illumeo 6 лет назад

    Thank you

  • @Savo963
    @Savo963 8 лет назад

    Can you make some more videos about parsing xml files in python? Btw nice job here.

  • @erfelipe
    @erfelipe 5 лет назад

    Thanks

  • @oluwanfemi
    @oluwanfemi 5 лет назад

    nice thanks bruh

  • @dwaipayanroy7319
    @dwaipayanroy7319 7 лет назад +3

    Fantastic tutorial for novices like me! May be you can also show how to obtain the xml file from the parent website.

    • @TheOPtmal
      @TheOPtmal 4 года назад

      import requests
      dom = requests.get("Web Path to the XML file")

  • @aldebaranmay
    @aldebaranmay 9 лет назад

    Great)

  • @eduardodalpogeto9419
    @eduardodalpogeto9419 3 года назад

    Whenever I try to print the dom it doesn't work, even after importing the XML.etree

  • @Karmihir
    @Karmihir 3 года назад

    How to handel when we have multiple xml file in a directory. Ex. XML Stracture is similar with updated data

  • @leonardgabrielson1013
    @leonardgabrielson1013 8 лет назад

    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!

    • @LabHatta
      @LabHatta 3 года назад

      fix this by add getroot() method at dom variable
      dom = ElementTree.parse(file_name).getroot()

  • @ambermeows150
    @ambermeows150 7 лет назад +7

    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?

    • @mikeckennedy
      @mikeckennedy  7 лет назад

      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.

    • @ambermeows150
      @ambermeows150 7 лет назад +1

      Thanks mike! Awesome content, i'm new to python programming and will purchase your python jumpstart course and then move on from there (:

  • @rahulnarang1515
    @rahulnarang1515 4 года назад

    how to convert to dataframe?

  • @chengdi123000
    @chengdi123000 6 лет назад

    Hi Michael,
    Element tree is a different way to process XML. DOM is another way. You may mixed them.

  • @Badar1980
    @Badar1980 9 лет назад

    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?

    • @mikeckennedy
      @mikeckennedy  9 лет назад +1

      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.

    • @Badar1980
      @Badar1980 9 лет назад

      Great, will check it out, thanks!

  • @InBackSound
    @InBackSound 9 лет назад

    Tell us about the XML parsing, when there is a namespace in file, please

    • @mikeckennedy
      @mikeckennedy  9 лет назад

      InBackSound Sure, this SO question has a pretty good answer: stackoverflow.com/questions/14853243/parsing-xml-with-namespace-in-python-via-elementtree

  • @Sharyf
    @Sharyf 6 лет назад

    Cool. Will it parse variable in memoy or websites response as well as a file?

    • @mikeckennedy
      @mikeckennedy  6 лет назад +1

      Sure, it will take a string so you can read the web response or stringify the variable into XML.

  • @dranoc5879
    @dranoc5879 2 года назад

    after you parse the course title, can you send those titles to the school web server and request for an xml file?

    • @mikeckennedy
      @mikeckennedy  2 года назад

      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.

  • @AntiRacistWarrior
    @AntiRacistWarrior 3 года назад

    Hello there, which is better xmltree or bs4 for parsing xml?

    • @mikeckennedy
      @mikeckennedy  2 года назад

      XmlTree I would think, if it's well formed XML.

  • @nicachipal1
    @nicachipal1 5 лет назад

    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!

    • @mikeckennedy
      @mikeckennedy  5 лет назад +1

      Here you go: stackoverflow.com/questions/18308529/python-requests-package-handling-xml-response

    • @nicachipal1
      @nicachipal1 5 лет назад

      @@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.

  • @rmt3589
    @rmt3589 2 года назад +1

    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.

    • @mikeckennedy
      @mikeckennedy  2 года назад +1

      I think it's just PyCharm. Maybe needs the pro version but I think the community PyCharm also understands HTML/XML.

    • @rmt3589
      @rmt3589 2 года назад +1

      @@mikeckennedy Thanks! I'll look into it!

  • @guxtAv123
    @guxtAv123 6 лет назад

    What is the name of the IDE that you're using?

  • @bob336nc
    @bob336nc 5 лет назад

    Yeah but, how did you get the xml file into PyCharm??

    • @mikeckennedy
      @mikeckennedy  5 лет назад

      I had already downloaded it into a subfolder at the beginning of the video.

  • @whichdude420
    @whichdude420 4 года назад

    What if the XML file does not have the tag? How would you overcome this problem?

    • @mikeckennedy
      @mikeckennedy  4 года назад

      I think it always has to have some top level single tag.

    • @whichdude420
      @whichdude420 4 года назад

      @@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!

    • @mikeckennedy
      @mikeckennedy  4 года назад

      @@whichdude420 Perfect!

  • @amanatansari5108
    @amanatansari5108 3 года назад

    was reed.xml a semi structured file?

    • @mikeckennedy
      @mikeckennedy  3 года назад

      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

  • @riyazbasha8227
    @riyazbasha8227 3 года назад

    what is dom...from where that comes from

    • @mikeckennedy
      @mikeckennedy  3 года назад

      Document Object Model (DOM): developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction

  • @lucaslucs3403
    @lucaslucs3403 4 года назад

    doesnt work

  • @user-uk9rw4re3g
    @user-uk9rw4re3g 3 года назад

    😀😱😤💩💋🤧🤮

  • @ChristianRRL
    @ChristianRRL 4 года назад

    Talks too fast

  • @MurderfaceWill
    @MurderfaceWill 6 лет назад

    3:00 There are only two genders!

  • @RagHelen
    @RagHelen 7 лет назад

    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?