网页浏览器搜索是如何实现的? [英] How is web browser search implemented?

查看:573
本文介绍了网页浏览器搜索是如何实现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在java中搜索桌面应用程序来实现,突出的多个的短语在 HTML 文件,就像它在Web浏览器中完成,因此 HTML标签(在< > )被忽略但一些标签,如&LT ; b> 的arent忽略。举例而言,当搜索每桌文本 ...每个< B>桌< / B>已经名称... 将突出,但在文字 ...各有< / P>< P>表... ,会不会高亮,因为< P> 标记中断文本意义结果
在Web浏览器中是这样莫名其妙地实现,我怎么能得到这个执行?或者是有在网络上的一些源?我试图谷歌,但没有成功:(

I want to implement in desktop application in java searching and highlighting multiple phrases in html files, like it is done in web browsers, so html tags (within < and >) are ignored but some tags like <b> arent ignored. When searching for example each table in text ...each <b>table</b> has name... will be highlighted, but in text ...has each</p><p> Table is... it will be not highlighted, because the <p> tag interrupts the text meaning.
in web browser is this somehow implemented, how can I get to this implementation? or is there some source on the net? I tried google, but without success :(

推荐答案

而不是实际的HTML中搜索文件浏览器上的HTML渲染输出的搜索

Instead of searching inside the actual HTML file the browsers search on the rendered output of that HTML.

找一个合适的HTML渲染器,并得到了其作为文本输出。使用适当的字符串搜索算法上的文本输出,然后搜索。

Get a suitable HTML renderer and get its output as text. Then search on that text output using appropriate string searching algorithms.

将导致所提供的HTML输出一个换行符,你在你的问题突出的例子,因此普通的字符串搜索算法将表现为你期望的那样。

The example that you highlighted in your question would result in a newline character in the rendered HTML output and hence a normal string searching algorithm will behave as you expect.

这篇关于网页浏览器搜索是如何实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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