0

div 内のコンテンツを選択しようとしていますが、この div にはテキストと追加のタグが含まれています。内部の最初の div を選択したくありません。私はこのセレクターを試していましたが、テキストなしでタグのみを提供します

//div[@class='contentDealDescriptionFacts cf']/div[@class='viewHalfWidthSize' and position()=2]/*[not(@class='subHeadline')]

私に問題を与えているdivはこれです:

<div class="viewHalfWidthSize">
    .......
</div>

<div class="viewHalfWidthSize">
    <div class="subHeadline firefinder-match">The Fine Print</div> <----------Except this div I want everything inside of this div!!
    <strong class="firefinder-match">Validity: </strong>
    Expires 27 June 2013.
    <br class="firefinder-match">
    <strong class="firefinder-match">Purchase: </strong>
    Limit 1 per 2 people. May buy multiple as gifts.
    <br class="firefinder-match">
    <strong class="firefinder-match">Redemption: </strong>
    Booking required online at
    <a target="_blank" href="http://grouponbookings.co.uk/lautre-pied-march/"      class="firefinder-match">http://grouponbookings.co.uk/lautre-pied-march/</a>
. 48-hour cancellation policy; late cancellation incurs a £30 surcharge per person.
    <br class="firefinder-match">
    <strong class="firefinder-match">Further information: </strong>
    Valid Mon-Sun midday-2.45pm; Mon-Wed 6pm-10.45pm. Must be 18 or older, ID may be   requested. Valid only on set tasting menu only; menu is dependent on market changes and seasonality and is subject to change. Max. two hours seating time. Discretionary service charge will be added to the bill based on original price. Original value verified 19 March 2013 at 9.01am.
   <br class="firefinder-match">
   <a target="_blank" href="http://www.groupon.co.uk/universal-fine-print" style="color: #339933;" class="firefinder-match">See the rules</a>
that apply to all deals.
</div>
4

1 に答える 1

0

*要素ノードに一致し、テキスト ノードには一致しません。に置き換え*node()、すべてのノード タイプを選択してみてください。

XPath が行っていることを分析するには、次のようにします。

//クラス 'contentDealDescriptionFacts cf' を持つ divのドキュメント ( ) 内の任意の場所を探しています。

次に、 class も持つ 2 番目の div を探していますviewHalfWidthSize。これはクラスを持つ 2 番目の div ではなく、2 番目の div にそのクラスがあることに注意してください。したがって、そのクラスの div が 3 番目と 4 番目の場合、クラスの 2 番目の div には何も一致しませんposition() = 4。2 番目のviewHalfWidthSizediv が必要な場合は、 [@class='viewHalfWidthSize'][position()=2].

最後に、 class なしですべての要素の nodelist を返していますsubHeadline。を に変更する*node()、すべてのノードのノードリストが取得されます。


次の XPath:

//div[@class='contentDealDescriptionFacts cf']/div[@class='viewHalfWidthSize' and position()=2]/node()[not(name(.)='div' and position() = 1)]

最初の子ノードが無視したい div である限り、必要なものを返す必要があります。

次のように変更した場合:

//div[@class='contentDealDescriptionFacts cf']/div[@class='viewHalfWidthSize' and position()=2]/node()[position() != count(../div[1]/preceding-sibling::node()) + 1]

その後、関係なく動作するはずです。ノードリストを返し、最初の div の前に先行ノードがいくつあるかを計算し、位置がそれより 1 つ大きくないことを確認し (つまり、最初の div の位置)、それをリストから除外します。


さらに別の方法として、元のソリューションを変更することもできますが、代わりに行うnot(@class='subHeadline')必要があります

not(contains(concat(' ', @class, ' '), ' subHeadline '))

subHeadlineクラスがスペースで区切られていると仮定して、クラス属性が文字列のどこかに含まれているかどうかを確認します。これは、クラスを持つフラグメントと一致します"subHeadline firefinder-match"

于 2013-03-26T11:56:43.270 に答える