简体   繁体   中英

Xpath selector Issue in the html

I am having an issue with getting the Xpath from two peace's of html but they show the same information.

Mark up One

<td class="tdRow1Color" width="100%">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr><td class="plaintextbold">Item Number:&nbsp;1258</td></tr>
        <tr><td><img alt="" src="images/clear.gif" width="1" height="10" border="0"></td></tr>
    <tr>
        <td class="plaintext" valign="middle">&nbsp;<img src="../images/0note.gif" border="0" align="absmiddle">&nbsp;<a class="prodlink" href="writeReview.asp?number=1258"><i><u>Be the first to review this item</u></i></a></td>
            </tr>   
                <tr><td><img alt="" src="images/clear.gif" width="1" height="10" border="0"></td></tr>                    
         <tr><td class="plaintext"><b>RRP £50.00 - Now £39.99</b>          </td>

Mark up Two

<tr><td class="tdRow1Color" width="100%">
    <table width="100%" cellpadding="0" cellspacing="0" border="0">         
        <tr><td class="plaintextbold">Item Number:&nbsp;2525</td></tr>
            <tr><td><img alt="" src="images/clear.gif" width="1" height="10" border="0"></td></tr>
                <tr>
                <td class="plaintext" valign="middle">&nbsp;<img src="../images/0note.gif" border="0" align="absmiddle">&nbsp;<a class="prodlink" href="writeReview.asp?number=2525"><i><u>Be the first to review this item</u></i></a></td>
                </tr>   
                <tr><td><img alt="" src="images/clear.gif" width="1" height="10" border="0"></td></tr>
                 <tr><td class="plaintext">RRP £45 - Now £38                       </td></tr>

The issue which I am having is because the two markup are different to get to the RRP prices is not working at the moment I am using the xpath

"//td[@class='tdRow1Color']/descendant::td | //td[@class='tdRow1Color']/descendant::b "

But this doesn't seem to working I was just wondering is there any way of getting the RRP price when they have the <b> and also when its just straight after the <td class "plaintext" > RRP. Thanks for any advice which you can give

You have several <td class="plaintext"> in your input HTML, not only for RRP. So I suggest you test the "RRP" string at the beginning of a text node in your XPath.

Something like this should work in both cases:

//td[@class='tdRow1Color']//td[@class='plaintext']//text()[starts-with(., 'RRP')]

以下XPath对我有用:

( //td[@class='tdRow1Color']/descendant::td[last()] | //td[@class='tdRow1Color']/descendant::b[last()] )/text()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM