开发者

How to turn off validation in Nokogiri?

I need to insert HTML 5 video tag t开发者_开发知识库o some places of HTML document, being parsed with Nokogiri.

Since it does't supports HTML 5 (afaik), it throws an exception, because the document is not valid in terms of HTML 4.0.

Is it possible to switch the validation off ?


It would help if you would show some sample code demonstrating the problem, along with the error you are seeing.

Nokogiri should parse HTML fine as it uses a lenient mode for HTML. I switched to Nokogiri several years ago because I had some HTML and RSS feeds that caused Hpricot to explode. Nokogiri would occasionally get mad because a page was full of errors, but at least the were ways to get at it. Rescue the exception, then check your doc.errors to see what Nokogiri thinks the problem is.

Something like this should help:

require 'nokogiri'

doc = Nokogiri::HTML('<html><body>...</body></html>')
puts doc.errors if (doc.errors.any?)
...
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜