Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YQL How to use wildcard in XPath

Tags:

xpath

yql

I have a malformed page to scrape, and have had a hard time getting the correct XPath for YQL. I can scrape individual fields that I need using, for example:

//*[@id="cell_12345"]

But what I really need to do is return all elements who's ID begins with cell_. Something like:

//*[@id="cell_"*]

How do I do this?

Also, if anybody can point me to a good XPath reference it would be very helpful.

Thanks!

like image 471
user191688 Avatar asked Mar 31 '10 22:03

user191688


People also ask

How to add wildcard in XPath?

We generally use an asterisk (*) while writing XPaths. This is called a Wildcard character. //input[@*='demo'] -> Any “input” node who contains an attribute value as “demo” for any attribute.

Can we use wildcard in XPath?

XPATH allows the use of wildcards to write more robust path expressions where the use of specific path expressions is either impossible or undesirable. matches any element node.

What does the wildcard operator * Do in XPath?

Explanation of XPath Wildcard This type of wildcard matches any given attribute in the document. Appears in the expression as if it is nested. It matches nodes of any type like text, attribute, namespace or comment whatever it is.


1 Answers

Something like

//*[starts-with(@id, 'ceil_')]

should do nicely.

As for an xpath reference, once you know the syntax and the axis, just any old function reference should help. This was the first one google: http://www.w3schools.com/xpath/xpath_functions.asp

like image 68
Paul Tarjan Avatar answered Sep 19 '22 04:09

Paul Tarjan