2014-01-09 58 views
0

這是我一起工作:過濾器/排除的XPath提取

<div class="Pictures zoom"> 

<a title="Productname 1" class="zoomThumbActive" rel="{gallery: 'gallery1', smallimage: '/images/2.24198/little_one.jpeg', largeimage: '/images/76.24561/big-one-picture.jpeg'}" href="javascript:void(0)" style="border-width:inherit;"> 

<img title="Productname 1" src="/images/24.245/mini-doge-picture.jpeg" alt="" /></a> 

<a title="Productname 1" rel="{gallery: 'gallery1', smallimage: '/images/2.24203/small_one.jpeg', largeimage: '/images/9.5664/very-big-one-picture.jpeg'}" href="javascript:void(0)" style="border-width:inherit;"> 

<img title="Productname 1" src="/images/22.999/this-picture-is-very-small.jpeg" alt="" /></a> 

<div> 

使用以下XPath:

/html//div[@class='Pictures zoom']/a/@rel 

輸出變爲:

{gallery: 'gallery1', smallimage: '/images/2.24198/little_one.jpeg', largeimage: '/images/76.24561/big-one-picture.jpeg'} 
{gallery: 'gallery1', smallimage: '/images/2.24203/small_one.jpeg', largeimage: '/images/9.5664/very-big-one-picture.jpeg'} 

是否有可能過濾提取,所以intread以上,我只得到這些:

/images/76.24561/big-one-picture.jpeg 
/images/9.5664/very-big-one-picture.jpeg 

我只想把一切都砍你不想要的部分,並

劉康使用和substring-afterlargeimage: '之間'}

最好的問候,

回答

1

substring-before

使用XPath 1.0,這隻能用於單個結果(因此您無法使用單個XPath調用來獲取包含在一個文檔中的所有URL)。這個查詢將返回的第一個網址:

substring-before(substring-after((//@rel)[1], "largeimage: '"), "'") 

的XPath 2.0允許您運行功能軸的步驟。這個查詢將返回所有網址,你正在尋找視爲單個標記:

//@rel/substring-before(substring-after(., "largeimage: '"), "'") 
+0

可悲的是,我不能使用XPath 2.0,但是這是最適合我的。謝謝! –