-
Recently Browsing 0 members
- No registered users viewing this page.
-
Similar Content
-
Download Natural Language Processing with Python (worth $39.99) for free
By Steven P.,
- ebook offer
- sponsored
- (and 2 more)
- 0 replies
- 0 views
-
Offensive Security Using Python eBook (worth $39.99) free download ends today
By News Staff,
- ebook offer
- sponsored
- (and 4 more)
- 0 replies
- 0 views
-
Offensive Security Using Python eBook (worth $39.99) is still free to download
By Steven P.,
- ebook offer
- sponsored
- (and 2 more)
- 0 replies
- 0 views
-
Download Offensive Security Using Python: A hands-on guide ($39.99 Value, now FREE)
By News Staff,
- ebook offer
- sponsored
- (and 2 more)
- 0 replies
- 0 views
-
Learn Python Programming, Fourth Edition ($35.99 Value) free eBook download
By News Staff,
- ebook offer
- sponsored
- (and 1 more)
- 0 replies
- 0 views
-
Question
Snowstorm
Hey guys,
Extremely frustrating problem, have wasted hours on this and can't find a solution.
I'm using dom/minidom through Python and can't use any other external Python modules.
Basically, we have the following example XML:
What I'm attempting to do is only pull data from the first [i]c[/i] of every [i]b[/i] element which is nested inside [i]a[/i]. All I'm able to do at the moment is pull all data contained in all available [i]c[/i]'s.
sText = dom.getElementsByTagName('a')
for node in sText:
sTextList = node.getElementsByTagName('c')
for i in sTextList:
dataText = i.firstChild.data
print dataText.encode('utf-8'), "<br />"
[/CODE]
Currently, all this achieves is:
1
2
3
1
2
3
1
2
3
[/CODE]
Is there a way I just pull the FIRST [i]c[/i] (as in, only "1") instead of all of them with the above code? This is driving me insane...
Thanks in advance!
Link to comment
https://www.neowin.net/forum/topic/1118303-python-extracting-specific-things-from-xml/Share on other sites
5 answers to this question
Recommended Posts