需要从Html中提取一些数据,如下所示:
<div class="r_tbar0 positionrelative">
<h3>Financials</h3>
</div>
<table class="r_table1 text2" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th scope="row" align="left"></th>
<th scope="col" id="Y0" align="right">2007-12</th>
<th scope="col" id="Y1" align="right">2008-12</th>
<!--More columns here-->
<th scope="col" id="Y9" align="right">2016-12</th>
<th scope="col" id="Y10" align="right">TTM</th>
</tr>
</thead>
<tbody>
<tr class="hr">
<td colspan="12"></td>
</tr>
<tr>
<th class="row_lbl" scope="row" id="i0">Revenue <span>USD Mil</span></th>
<td headers="Y0 i0" align="right">5,858</td>
<td headers="Y1 i0" align="right">5,808</td>
<!--More cells here-->
<td headers="Y9 i0" align="right">4,272</td>
<td headers="Y10 i0" align="right">4,955</td>
</tr>
<tr class="hr">
<td colspan="12"></td>
</tr>
<tr>
<th class="row_lbl" scope="row" id="i1">Gross Margin %</th>
<td headers="Y0 i1" align="right">37.4</td>
<td headers="Y1 i1" align="right">39.9</td>
<!--More cells here-->
<td headers="Y9 i1" align="right">23.4</td>
<td headers="Y10 i1" align="right">33.5</td>
</tr>
<!--More rows here-->
<tr class="hr">
<td colspan="12"></td>
</tr>
</tbody>
</table>我希望通过搜索“收入”行,然后查看2007年专栏,从关键比率页面中提取2007年收入数据XPATH。
2007年收入的XPATH位置:
//*[@id="financials"]/table/tbody/tr[2]/td[1]tr2表示收入对齐的行。然而,如果我有一个计划,观察多只股票,我想确保tr2仍然关注收入。
我尝试了以下XPATH的多个版本,它返回一个空值。(我正在使用XPATH google扩展)
//*[@id="financials"]/table/tbody/tr[contains(text(),'Revenue')]/td[1]收入行的外部html代码:
<th class="row_lbl" scope="row" id="i0">Revenue <span>USD Mil</span></th>2007年收入外部html代码:
<td align="right" headers="Y0 i0" class="">5,858</td>更新
以下是我写的答案:
//*[@id='financials']//td[contains(@headers,'i0')][1]2017年收入数据5,858
发布于 2017-12-09 00:41:56
在"Financials“表中,”th“是tr,而不是tr。通过引用header标记的td属性,可以获取该表的列或行中的所有单元格。列是Y0..Yn,行是i0..in,例如:
第一列有头Y0
//*@id='financials'//tdcontains(@headers,'Y0')
第一行有头i0
//*@id='financials'//tdcontains(@headers,'i0')
诸若此类
https://stackoverflow.com/questions/47723444
复制相似问题