[英]xpath with lxml for Python to get data
<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>
I am trying to extract data for 'Trailing EPS' to get data '1.87198'. 我正在尝试提取“跟踪EPS”的数据以获取数据“ 1.87198”。 There are many data with this format with different name, like EPS, ROE and etc 有许多这种格式的数据具有不同的名称,例如EPS,ROE等
tree.xpath('//th[contains(normalize-space(span), "EPS")]/sup[@class = "sic_legend"]/td/text()')
I get nothing out from it. 我什么也没得到。
The td
element is not a child of the sup
element. td
元素不是sup
元素的子元素。 Use the fact that th
and td
are siblings : 使用th
和td
是兄弟姐妹的事实:
//th[contains(span, "EPS")]/following-sibling::td/strong/text()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.