【发布时间】:2018-02-07 13:37:20
【问题描述】:
我需要可靠的方法来获取此 url "http://www.screener.com/v2/stocks/view/5131" 的 xpath
但是,在想要的数据之前有太多的空白,并且不可靠。
我需要的部分是下面的html中的11.48,9.05,11.53:
<div class="table-responsive">
<table class="table table-hover">
<tr>
<th>Financial Year</th>
<th class="number">Revenue ('000)</th>
<th class="number">Net ('000)</th>
<th class="number">EPS</th>
<th></th>
</tr>
<tr>
<td>30 Nov, 2017</td>
<td class="number">205,686</td>
<td class="number">52,812</td>
<td class="number">11.48</td>
<td></td>
</tr>
<tr>
<td>30 Nov, 2016</td>
<td class="number">191,301</td>
<td class="number">41,598</td>
<td class="number">9.05</td>
<td></td>
</tr>
<tr>
<td>30 Nov, 2015</td>
<td class="number">225,910</td>
<td class="number">51,082</td>
<td class="number">11.53</td>
<td></td>
</tr>
我的代码如下
from lxml import html
import requests
page = requests.get('http://www.screener.com/v2/stocks/view/5131')
output = html.fromstring(page.content)
output.xpath('//tr/td/following-sibling::td/text()')
如何更改代码,使其能够从上面的表格中稳健地获取三个数字?
我只想要输出11.48,9.05,11.53但我无法摆脱表格中的太多数据
【问题讨论】: