[英]Xpath to get text of all node but the one with specific tag
因此,我得到了這種類型的html模式:
<table id="proposal-details" class="details">
<tbody><tr>
<th>
Application type:
</th>
<td>
P
</td>
</tr>
<tr>
<th>
Proposed development
</th>
<td>
Prune 1 x Eucalyptus
</td>
</tr>
<tr>
<th>
Date received:
</th>
<td>
06 Feb 2015
</td>
</tr>
<tr>
<th>
Registration date:
<br>
(Statutory start date)
</th>
<td>
06 Feb 2015
</td>
</tr>
我已經得到了XPath來捕獲所有的次 ; 一切順利,一路到最后個文本登記日期:在這里我其實不需要的BR文本被選中。
我已經解決了這個問題,問題出在這個xpath上,
len(response.xpath("//table//tr//th[not(.//br)]/text()").extract())
整個標簽被忽視。 有什么建議嗎?
這是我得到的輸出:
[u' Application type: ',
u' Proposed development ',
u' Date received: ']
我實際需要的注冊日期:列表中沒有(法定開始日期) 。
據我了解你的問題,你想獲得的所有文字th
元素,但忽視之后的文本<br>
。 如果是這樣,則以下XPath
//table//tr//th/text()[not(preceding-sibling::br)]
當應用於您的輸入時會產生結果
Application type:
Proposed development
Date received:
Registration date:
您使用的XPath只是忽略每個th
有孩子的br
:
th[not(.//br)]
而th/text()[not(preceding-sibling::br)]
檢索th
所有沒有前一個兄弟br
文本元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.