我正在尝试使用xpath从该html中获取死亡年龄。我的问题是它没有类名或选择器来获取信息。有没有办法获取3rd类统计信息,然后在其内部获取3rd a href,并在其内部获取年龄跨度?
这是我到目前为止的内容,但是没有用
=IMPORTXML(B3,"//div[@class='stat'][3]")
html代码:
<div class="is-flex">
<div class="col-xs-6 col-md-12">
<div class="stat box">
<i class="icn icn-birthday"></i>
<h6> Birthday </h6>
<a href="/february26.html"><span class="hidden-sm">February</span><span class="hidden-xs hidden-md hidden-lg">Feb</span> 26</a>, <a href="/year/1932.html">1932</a>
</div>
</div>
<div class="col-xs-6 col-md-12">
<div class="stat box">
<i class="icn icn-birthplace"></i>
<h6>Birthplace</h6>
Kingsland,
<a href="/birthplace/arkansas.html"> AR </a>
</div>
</div>
<div class="col-xs-6 col-md-12">
<div class="stat box">
<i class="icn icn-age"></i>
<h6>Death Date</h6><a href="/deceased/day/september12.html">Sep 12</a>, <a href="/deceased/2003.html">2003</a> (<a href="/deceased/age/71.html"><span class="hidden-sm">age </span>71</a>)
</div>
</div>
<div class="col-xs-6 col-md-12">
<div class="stat box">
<i class="icn icn-horiscope"></i>
<h6>Birth Sign</h6><a href="/astrology/pisces.html">Pisces</a>
</div>
</div>
</div>
答案 0 :(得分:1)
此xpath表达式:
//div[@class='stat box'][1]/a[3]/text()
应输出:
71
答案 1 :(得分:0)
您可以使用以下XPath-1.0表达式选择年龄值:
=IMPORTXML(B3,"//div[contains(@class,'stat') and contains(h6,'Death Date')]/a[contains(@href,'/deceased/age')]/span/following::text()")
返回71
,包括一些空格。
要摆脱前导和尾随空格,请使用
=IMPORTXML(B3,"normalize-space(//div[contains(@class,'stat') and contains(h6,'Death Date')]/a[contains(@href,'/deceased/age')]/span/following::text())")