什么是“解析器必须类似于浏览器"?方法? [英] What does "the parser must be similar to the browser" means?

查看:103
本文介绍了什么是“解析器必须类似于浏览器"?方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我是Web开发的新手.我正在一个必须使用html解析器的项目中.

我一直在使用Tagsoup.建议我使用与浏览器非常相似的解析器.

我知道浏览器对HTML页面的处理方式不同,但是类似于浏览器的解析器"是什么意思?

如何检查解析器是否类似于浏览器?

感谢

解决方案

基本上不同的浏览器对同一标记的处理方式略有不同(或在某些情况下根本不同).建议您确保浏览器能够创建文档对象模型(DOM),该对象类似于浏览器提供的DOM.如果我是您,则希望检查以与符合标准的浏览器兼容的方式来生产DOM的能力,换句话说,不要针对IE6对其进行测试(我差一点就说不测试...但是那样太讽刺了.)

您可以做的是渲染生成的DOM,然后将其与在您选择的浏览器中渲染时丢弃的DOM进行比较.为此,您可以使用 [ ^ ]脚本. /blockquote>

Hello,

I am new to web development. I am working on a project where I have to use a html parser.

I have been using Tagsoup. I have been advised to use parsers that are very similar to the browser.

I know that browsers treat HTML pages differently but, what does "parser similar to browser" mean?

How can I check if a parser is similar to the browser?

Thanks

解决方案

Basically different browsers treat the same markup in slightly (or radically in some cases) different ways. What you are being advised here is to ensure that your browser is capable of creating a Document Object Model (DOM), which is similar to the DOM provided by a browser. If I were you, I''d look to check the ability to produce the DOM in a fashion that is compatible with a standards compliant browser, in other words don''t test it against IE6 (I nearly said i.e. don''t test... but that would have been too ironic).

What you could do is render the DOM you produce out, and then compare it to the DOM dumped out when you render it in the browser of your choice. To do this, you can dump out the document using this[^] script from the browser.


这篇关于什么是“解析器必须类似于浏览器"?方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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