如果前面的元素 text() 匹配特定条件,我想提取一个元素。例如,
<html>
<div>
<table class="layouttab">
<tbody>
<tr>
<td scope="row" class="srb">General information: </td>
<td>(xxx) yyy-zzzz</td>
</tr>
<tr>
<td scope="row" class="srb">Website: </td>
<td><a href="http://xyz.edu" target="_blank">http://www.xyz.edu</a>
</td>
</tr>
<tr>
<td scope="row" class="srb">Type: </td>
<td>4-year, Private for-profit</td>
</tr>
<tr>
<td scope="row" class="srb">Awards offered: </td>
<td>Less than one year certificate<br>One but less than two years certificate<br>Associate's degree<br>Bachelor's
degree
</td>
</tr>
<tr>
<td scope="row" class="srb">Campus setting: </td>
<td>City: Small</td>
</tr>
<tr>
<td scope="row" class="srb">Related Institutions:</td>
<td><a href="?q=xyz">xyz-New York</a>
(Parent):
<ul>
<li style="list-style:circle">Berkeley College - Westchester Campus</li>
</ul>
</td>
</tr>
</tbody>
</table>
</div>
</html>
现在,如果前一个元素在 text() 属性中具有“Website:”,我想提取 URL。我正在使用带有scrapy 0.14的python 2.x。我能够使用单个元素提取数据,例如
item['Header_Type']= site.select('div/table[@class="layouttab"]/tr[3]/td[2]/text()').extract()
但是,如果缺少网站参数并且 tr[3] 向上移动并且我在网站元素中得到“类型”,在类型中得到“提供的奖励”,这种方法就会失败。
xPath 中是否有特定命令,例如,
'div/table[@class="layouttab"]/tr/td[2] {if td[1] has text = "Website"}
提前致谢。