bkcollection
bkcollection

Reputation: 924

Python: Xpath unable to get a number

I would like to get the info of '89.34' in the html

    <div class="MarketsTable-container-2b0AP KeyMetrics-table-Ow-Ln">
<table class="table-container two_columns MarketsTable-borderless-1FRfN MarketsTable-headerless-1ZF6D MarketsTable-condensed-2ragd">
<tbody><tr class="data"><th class="MarketsTable-label-_JI6s" cellPadding="1" cellSpacing="1" scope="row"><div class="TextLabel__text-label___3oCVw TextLabel__gray___1V4fk TextLabel__regular___2X0ym MarketsTable-label-_JI6s">P/E excl. Extra Items (Annual)</div></th>
<td class="MarketsTable-value-FP5ul" cellPadding="1" cellSpacing="1">
<span class="TextLabel__text-label___3oCVw TextLabel__black___2FN-Z TextLabel__regular___2X0ym digits MarketsTable-value-FP5ul">89.34</span></td></tr><tr class="data">

I try xpath('//div[contains(., "P/E incl. Extra Items (TTM)")]/following-sibling::td[1]/text()')but return nothing. Please advise. The url is as below https://www.reuters.com/companies/AALI.JK/key-metrics

Upvotes: 1

Views: 32

Answers (1)

supputuri
supputuri

Reputation: 14135

Try the below xpath.

//div[contains(., 'P/E incl. Extra Items (TTM)')]/../following-sibling::td[1]/span/text()

or you can use parent::th

//div[contains(., 'P/E incl. Extra Items (TTM)')]/parent::th/following-sibling::td[1]/span/text()

enter image description here

Upvotes: 1

Related Questions