python - Return a parent tag attribute from selected child -


<tags>       <parent id="parent id">      <mid>       <child attr="child value" 

i have piece of code selecting attribute values xml correspond "child value".

i need have "parent value", relate 2 items, future use.

my code locates , retrieves child values, i'm having difficulty getting value parent id. correct syntax this?

currently code similar this:

taglist = [] parent in soup.find_all('tags'):     each in parent.find_all('child'):         taglist.append(repr(each['attr'])) 

i want retrieve, in example parent id value, child selected.

there relevant find_parent() method:

child.find_parent("parent", id=true)["id"] 

Comments

Popular posts from this blog

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -