Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 XML Parsing - Find a specific text (ElementTree)
#1
Hi all,

I have a problem to parse a specific text from a xml file.

What I need is the Value (BB001234) of the IDTAG but I didn't know how to grab them.

Here is my full .xml file and my python code.
The problem is that the quantity of the "<DataPoint> ### </DataPoint>" can change.

Hopefully someone can help me.

Thank you
TeraX

import os
from xml.etree import ElementTree

file_name = 'cumulus.xml'
full_file = os.path.abspath(os.path.join('data', file_name))
dom = ElementTree.parse(full_file)

assy = dom.findall('WorkOrders/CumulusWorkOrder/Assembly')

for c in assy:
    item = c.find('PartNumber').text
    serial = c.find('SerialLotNumber').text
    desc = c.find('Description').text.encode('utf-8')
    # idtag = c.find('IDTAG').text

    #print(' * {} - {} - {} - {}'.format(
    #    item, serial, desc, idtag
    #))
    print(' * {} - {} - {} - '.format(
        item, serial, desc
    ))
results:

Output:
$ python 1.py * 1234567 - 1234567.abcdef - Item Description -
cumulus.xml
Quote

Top Page

Messages In This Thread
XML Parsing - Find a specific text (ElementTree) - by TeraX - Oct-05-2018, 03:55 PM

Possibly Related Threads...
Thread Author Replies Views Last Post
  Getting a specific text inside an html with soup mathieugrimbert 9 279 Jul-10-2019, 12:40 PM
Last Post: mathieugrimbert
  ElementTree kkrish 2 287 Apr-27-2019, 01:36 AM
Last Post: kkrish
  Parsing infor from scraped files. Larz60+ 2 280 Apr-12-2019, 05:06 PM
Last Post: Larz60+
  Fetching and Parsing XML Data FalseFact 3 315 Apr-01-2019, 10:21 AM
Last Post: Larz60+
  [split] How to find a specific word in a webpage and How to count it. marpop 2 299 Mar-12-2019, 08:25 AM
Last Post: snippsat
  Selenium Parsing (unable to Parse page after loading) oneclick 6 594 Jan-13-2019, 03:10 AM
Last Post: oneclick
  XML parsing from URL mightyn00b 5 2,410 Nov-22-2018, 02:59 AM
Last Post: Larz60+
  How to find particular text from td tag using bs4 Prince_Bhatia 7 667 Sep-24-2018, 08:36 PM
Last Post: nilamo
  XML parsing and generating HTML page Python 3.6 Madhuri 2 535 Aug-24-2018, 02:48 PM
Last Post: snippsat
  webscraping - failing to extract specific text from data.gov rontar 2 564 May-19-2018, 08:01 AM
Last Post: rontar

Forum Jump:


Users browsing this thread: 1 Guest(s)