python - BeautifulSoup: Parse children by tag name -


i have xml coordinates this:

<geo>  <lat>52.5025100</lat>  <lng>13.3086000</lng> </geo> 

i can parse string of first , second child (that stored in list) this:

child_1=soup.find('geo').contents[1].get_text(strip=true) child_2=soup.find('geo').contents[3].get_text(strip=true) 

suppose have process several files , i'm not sure whether lat , long appear in above order, indexing not work because not reliable. rather parse lat , long tag-names children of geo.

this not work:

child_1=soup.find('geo').contents('lat').get_text(strip=true) 

so how achieve this?

note: lat , long appear several times in doc. therefore can't parse doc directly lat , long

you can directly access child elements of node using tag name:

geo = soup.find('geo') print geo.lat.get_text(strip=true) print geo.lng.get_text(strip=true) 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -