开发者

Multiple search with Hpricot

开发者 https://www.devze.com 2023-02-06 07:32 出处:网络
Had RTFM\'ed, but still puzzled. I need to get objects which satisfy at least one of the pr开发者_Go百科operty condition list.

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

精彩评论

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