大多数类似jQuery的HTML解析器用于Ruby [英] Most jQuery-like HTML parser for Ruby

查看:211
本文介绍了大多数类似jQuery的HTML解析器用于Ruby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我已经熟悉/喜欢jQuery,那么Ruby的哪个HTML解析器最容易使用?

这样的解析器可以让jQuery的整体理念 - - 获取一些HTML元素(使用CSS选择器)并对它们进行处理 - 另外还有所有jQuery DOM操作功能( prepend() after()等)。

显然,服务器端解析器无法支持jQuery事件,效果或AJAX功能。



编辑:Hpricot做得很好(例如, doc.search '#menu')。inner_html ) - 是否有更好的API? (当我Googlenokogiri v。hpricot时,我所得到的只是速度比较,我不在乎速度!我只是想要一个有趣/容易使用的图书馆!)

Hpricot >解决方案

>。它甚至在头版显示它:


Hpricot是一个非常灵活的HTML
解析器,基于田中Akira的HTree
和John Resig的jQuery,但是用C语言重新编写了
扫描器。我借用了这些商品的
(我认为是)最好的想法
Hpricot堆满
的乐趣。



What HTML parser for Ruby will I find easiest to use if I'm already familiar / in love with jQuery?

Such a parser would have jQuery's overall philosophy -- "grab some HTML elements (using CSS selectors) and do things with them" -- and in addition have equivalents for all of jQuery's DOM manipulation functionality (prepend(), after(), etc).

Obviously it wouldn't make sense for a server-side parser to support jQuery event, effect, or AJAX functionality.

Edit: Hpricot does this pretty well (e.g., doc.search('#menu').inner_html) -- is there anything with a better API? (When I Google "nokogiri v. hpricot" all I get are speed comparisons. I don't care about speed! I just want a library that's fun / easy to use!)

解决方案

You'd probably be most at home with Hpricot. Heck, it even says it right there on the front page:

Hpricot is a very flexible HTML parser, based on Tanaka Akira’s HTree and John Resig’s jQuery, but with the scanner recoded in C. I’ve borrowed (what I believe to be) the best ideas from these wares to make Hpricot heaps of fun to use.

这篇关于大多数类似jQuery的HTML解析器用于Ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆