简体   繁体   中英

python: xpath lxml to extract data

<td> <span class="data_lbl updated-daily">P/E Ratio <small class="data_meta">(including extraordinary items)</small></span> <span class="data_data"> <span class="marketDelta deltaType-negative">-69.83</span> </span> </td>

How to extract data PE Ratio data '-69.83' in a robust way? I want to point it straight to the P/E Ratio.

from lxml import html
import requests

StockData =['AASIA']
page_wsj1 = requests.get('http://quotes.wsj.com/MY/'+StockData[x]+'/financials')
wsj1 = html.fromstring(page_wsj1.content)
PE = wsj1.xpath('//td[contains(.,"P/E Ratio")]/text()')

but the result is ['','','','','']

wsj1.xpath('//td[normalize-space(span) = "P/E Ratio"]/span[@class = "data_data"]/span/text()')

also result []

//td[normalize-space(span/text()) = "P/E Ratio"]/span[@class = "data_data"]/span

要么

//td[contains(normalize-space(span), "P/E Ratio")]/span[@class = "data_data"]/span

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM