<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