简体   繁体   中英

PHP DOMXPath content match & select expression

I'm trying to match and select a bunch of cols of a table but don't get it working. Here's a simplified table:

<table>
 <tr>
  <td>Foo</td>
  <td>Bar</td>
  <td>Arb</td>
  <td>...</td>
 </tr>
 <tr>
  <td>Foo</td>
  <td>Rab</td>
 </tr>
</table>

So I want to get the TDs wich contain Bar and Arb and others but not Foo and nothing from the 2nd TR Block. Someone knows if this is possible with a XPath expression? Note: There's nothing static in there. The only way to get the correct cols is to match the first TDs content.

Don't know if my answer could help you out, but an adaptable XPath could look like:

//table/tr[1]/td[x] | //table/tr[1]/td[y] 

where x and y depends which column you'd like to target. The | computes two node-sets.

I'd also like to suggest you to install the XPath Checker Firefox AddOn ( https://addons.mozilla.org/en-US/firefox/addon/xpath-checker/ ) where you're able to play around with the xPath syntax, in order to trigger a particular DOM Element of a website.

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