2012-06-28 1 views
6

에서 BR 태그 후 텍스트를 추출 :XPath는 다음 줄에 <code>br</code> 태그 후 텍스트를 추출하는 방법 R

<div id='population'> 
    The Snow Leopard Survival Strategy (McCarthy <em>et al.</em> 2003, Table 
    II) compiled national snow leopard population estimates, updating the work 
    of Fox (1994). Many of the estimates are acknowledged to be rough and out 
    of date, but the total estimated population is 4,080-6,590, as follows:<br> 
    <br> 
    Afghanistan: 100-200?<br> 
    Bhutan: 100-200?<br> 
    China: 2,000-2,500<br> 
    India: 200-600<br> 
    Kazakhstan: 180-200<br> 
    Kyrgyzstan: 150-500<br> 
    Mongolia: 500-1,000<br> 
    Nepal: 300-500<br> 
    Pakistan: 200-420<br> 
    Russia: 150-200<br> 
    Tajikistan: 180-220<br> 
    Uzbekistan: 20-50 
</div> 

내가 가진 지금까지 같이 내가 붙어있어

xpathSApply(h, '//div[@id="population"]', xmlValue) 

하지만, 지금 ...

+3

여기에는 텍스트가 없습니다. _within_'
' tags ... 여러 태그 사이에 있습니까? 원하는 것을 명확히하고 싶을 수도 있습니다. 첫 번째 추측은''// div [@ id = "population"]/text() [preceding-sibling :: br] '' – Wrikken

+0

입니다. 대답으로 넣고 확인해 보겠습니다. – Kay

답변

18

텍스트가 노드라고 생각하면 도움이됩니다. <br/> '를 아래와 같이보다 사업부의 모든 텍스트들에 의해 검색 할 수 있습니다 :

//div[@id="population"]/text()[preceding-sibling::br and following-sibling::br] 

을 ...하지만 나는 당신이 원하는 게 아니에요 같아요

//div[@id="population"]/text()[preceding-sibling::br] 

기술적으로, <br/> 사이의 태그 의미 이 지점에서.

+0

나는 '사이에'편집했습니다. 정말 고마워요! – Kay

관련 문제