Skip to content
Advertisement

using “getElementsByTagName” to get tag in python

my XML file is

JavaScript

my code is

JavaScript

I want to get value of element with tagname ‘string name=”ID”‘

but the error comes

JavaScript

if i replace

JavaScript

to

JavaScript

the output comes

“nCGhwaZNpy6”

since its the first element of that list but second element is

“02.11.2013 Scott Mobile”

which also get saved in list which i don’t want

however there are two string tag with name=”ID” and name=”name” how to access the string tag with name=”ID” only

Advertisement

Answer

string name="ID" is not tag name. Only string is tag name.

You have to compare name attribute value for each string tag.

JavaScript

I recommed you to use lxml or BeautifulSoup.

Following is equivalent code using lxml.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement