2016-11-11 1 views
2
<th><span class="sic_edu_series_popup {keyword : 'EPS_STOCK'}">EPS</span> 
      (SGD) <sup class="sic_legend">a 
      , j 

    </sup></th> 
    <td><strong>1.89766</strong></td> 
    <th><span class="sic_edu_series_popup {keyword : 'TRAILING_EPS_STOCK'}">Trailing EPS</span> 
     (SGD) <sup class="sic_legend">e</sup></th> 
    <td><strong>1.87198</strong></td> 
    <th><span class="sic_edu_series_popup {keyword : 'NAV_STOCK'}">NAV</span> 
     (SGD) <sup class="sic_legend">b</sup></th> 
    <td><strong>18.5449</strong></td> 
    </tr> 

데이터 '1.87198'을 얻기 위해 'Trailing EPS'에 대한 데이터를 추출하려고합니다. EPS, ROE 등과 같이 이름이 다른 많은 데이터가 있습니다.파이썬에서 데이터를 가져올 xxpath xpath

tree.xpath('//th[contains(normalize-space(span), "EPS")]/sup[@class = "sic_legend"]/td/text()') 

나는 아무것도 얻지 못합니다.

답변

3

td 요소는 sup 요소의 하위 요소가 아닙니다.

//th[contains(span, "EPS")]/following-sibling::td/strong/text() 
+0

감사 : thtd형제이 사실을 사용합니다. 그것은 내가 원하는 데이터를 가지고 있지만 또 다른 두 요소를 포함합니다. 위의 편집 된 코드를 참조하십시오. – vindex

+0

@vindex 다음을 시도해보십시오 :'/ th [contains (span, "EPS")]/following-sibling :: td [1]/strong/text()' – alecxe

관련 문제