xpath和lxml用于Python获取

2024-06-17 19:29:48 发布

您现在位置:Python中文网/ 问答频道 /正文

<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>

我正在尝试提取“Trailing EPS”的数据,以获取数据“1.87198”。这种格式有很多不同名称的数据,如EPS、ROE等

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

我从中什么也得不到。你知道吗


Tags: stockepskeywordclasstdstrongseriesspan