<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>
如何以稳健的方式提取数据PE比率数据'-69.83'? 我想直接指向市盈率。python:xpath lxml提取数据
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()')
但结果是[ '', '', '', '', '']
wsj1.xpath('//td[normalize-space(span) = "P/E Ratio"]/span[@class = "data_data"]/span/text()')
也导致[]
你试过写点什么吗? – Dekel
这是一个重复的http://stackoverflow.com/questions/40488422/python-get-data-from-changing-span-class-using-lxml-xpath – Markus
你错过了一个'span'。 – Markus