Reputation: 1684
For an iOS app, I'm using an open source html parser called Hpple to scrape some data from a web page. The two tags I'm searching for are <td class="menugridcell">
and <td class="menugridcell_last">
I'm trying to create one xpath that searches for either tag. I unsuccessfully tried using the 'contains()' function:
NSString *queryString = @"//td[@class=contains(., 'menugridcell')]"
There should be 27 nodes that match this query, but oddly I was getting 1 (not even 0). I tried several variations, but I can't seem to find the right syntax.
For reference, here is how I searched for them separately
NSString *queryString = @"//td[@class='menugridcell']"
(returns 18 nodes)
NSString *queryString2 = @"//td[@class='menugridcell_last']"
(returns 9 nodes)
Upvotes: 0
Views: 51
Reputation: 89285
You can try this way :
//td[contains(@class, 'menugridcell')]
Possible alternatives are using starts-with()
as pointed by @pault. in comment :
//td[starts-with(@class, 'menugridcell')]
or using or
to select by one of two conditions :
//td[@class='menugridcell' or @class='menugridcell_last']
Anyway, it is a bit surprising to hear that the library you're using doesn't recognize contains()
function, because contains()
is available since XPath 1.0 spec.
Upvotes: 1