For HTML extraction, I believe many people have heard of or used htmlparser.
Htmlparser is a pure library written in Java for HTML Parsing. It is not dependent on other Java library files and is mainly used to transform or extract HTML. It cannot be said that it can parse HTML at a high speed, but its resolution quality is good and it is not prone to errors. To put it bluntly, htmlparser is currently the most powerful Java HTML parsing and analysis tool.
Htmlparser Project Website: http://htmlparser.sourceforge.net /.
For more information about how to get started with htmlparser, see the blog "Introduction to htmlparser". Of course, you can also refer to htmlparser learning and htmlparser usage.
The following is a simple htmlparser example for reading all the text on an HTML page.
1 Package Org.html parser; 2 Import Java. Io. file; 3 Import Java. Io. fileoutputstream; 4 Import Org.html parser. parser; 5 Import Org.html parser. lexer. cursor; 6 Import Org.html parser. nodes. tagnode; 7 Import Org.html parser. util. nodeiterator; 8 Import Org.html parser. util. nodelist; 9 10 Public Class Simplehtmlparse { 11 Public Static Void Main (string ARGs []) Throws Exception { 12 13 Parser = New Parser ("d :\\ html1.htm"); 14 // Parser = new Parser ("I: \ bbb.htm "); 15 Parser. setencoding ("GBK" ); 16 Nodelist list = parser. parse ( Null ); 17 String STR = List. tostring (); 18 System. Out. println (STR ); 19 20 Fileoutputstream output = New Fileoutputstream ( New File ("d :\\ 1.txt" )); 21 Byte B [] = Str. getbytes (); 22 For ( Int I: B ){ 23 Output. Write (I ); 24 } 25 Output. Close (); 26 } 27 }
In fact, there will be a lot of gains for in-depth research on HTML parsing.