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などの名前が異なるこの形式のデータは多数あります。Pythonでデータを取得するためのlxmlのxpath
tree.xpath('//th[contains(normalize-space(span), "EPS")]/sup[@class = "sic_legend"]/td/text()')
私はそれから何も得られません。
:
th
とtd
が兄弟であるという事実を使用してください。それは私が望むデータを持っていますが、それはまた別の2つの要素を含んでいます。上記の編集コードを参照してください。 – vindex@vindex大丈夫、次のようにしてください: '/ th [contains(span、" EPS ")]/following-sibling :: td [1]/strong/text()' – alecxe