开发者

Multiple search with Hpricot

Had RTFM'ed, but still puzzled. I need to get objects which satisfy at least one of the pr开发者_Go百科operty condition list.

E.g. divs, where class == "marked" OR class = "data" OR class = "comments"

For now emulated it manually, but is it possible with Hpricot standard abilities?


doc = Hpricot.parse(..your data...)
divs = doc.search("//div[@class='marked' or @class='data' or @class='comments']")

The search takes an xpath expression, and xpath allows logical and and or operators. See this great answer about a similar question: XPATH Multiple Element Filters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜