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 extract data pe ratio data '-69.83' in robust way? want point straight 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 result ['','','','','']

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 

or

//td[contains(normalize-space(span), "p/e ratio")]/span[@class = "data_data"]/span 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -