Conditional node selection with BS in Python

43 views
Skip to first unread message

Paul Kremershof

unread,
Apr 13, 2018, 6:36:46 PM4/13/18
to beautifulsoup
Hey all,

I'm unfortunately stuck with this problem. I have a large corpus XML file in which I wish to iterate through and select the <sn node if it contains elliptic="yes" of kind:
soup.find_all('sn', {"elliptic" : "yes"})

Once found, I want to get the very next <v node.

Exempt from the file:

 
<sentence id="4">
   
<f lem="-" pos="fg" punct="hyphen" wd="-"/>
   
<sn arg="arg1" elliptic="yes" entityref="lex" func="suj" tem="tem"/>
   
<grup.verb>
     
<v lem="ser" lss="C21.state-attributive" mood="indicative" num="s" person="3" pos="vsip3s0" postype="semiauxiliary" tense="present" wd="És"/>
   
</grup.verb>

So far, it was impossible to me to find a way to get his accomplished. Also because <v does not seem to be a child of <sn but rather a child of <grup.verb> (which gives me errors due to the dot).

Have you any idea to get this done? Have many thanks in advance
Best,Paul
Reply all
Reply to author
Forward
0 new messages