如何使用正则表达式解析Java中的HTML? [英] How to use regular expressions to parse HTML in Java?
本文介绍了如何使用正则表达式解析Java中的HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请问有人能告诉我一个简单的方法在Java中使用正则表达式在html文件中找到href和src标签吗?
然后,如何获取与标签关联的URL?
Please can someone tell me a simple way to find href and src tags in an html file using regular expressions in Java?
And then, how do I get the URL associated with the tag?
感谢您的任何建议。
推荐答案
使用正则表达式从中提取值HTML总是一个错误。 HTML语法要复杂得多,它可能首先出现,并且页面很容易捕捉到一个非常复杂的正则表达式。
Using regular expressions to pull values from HTML is always a mistake. HTML syntax is a lot more complex that it may first appear and it's very easy for a page to catch out even a very complex regular expression.
使用 HTML Parser 。另请参见有哪些优缺点领先的Java HTML解析器?
这篇关于如何使用正则表达式解析Java中的HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文