Extract the HTML content and place the txt text in Excel __html

Source: Internet
Author: User
Core Code

A package that needs to be introduced: Jxl-2.6.jar;
Source Package for content extraction: Jsoup-1.10.2.jar
-Read TXT file

            FIS = new FileInputStream (
                    "C:\\users\\administrator\\desktop\\app3\\123.txt");
                    FileInputStream gets the byte
            ISR = new InputStreamReader (FIS) from a file in the file system;//InputStreamReader is the bridge of byte flow to character stream,
            br = The new BufferedReader (ISR);//reads the contents of the file from the character input stream, encapsulating a new
                                            //InputStreamReader object while
            (str = br.readline ())!= NULL) {}//here corresponds to each line of TXT, processing data
Writing to Excel
           Writableworkbook book = Workbook.createworkbook (New File ("401-500.xls"));
            Generates a worksheet named "first page", and parameter 0 indicates that this is the first page
            writablesheet sheet = book.createsheet ("First page", 0);
            Label Templabel = new label (0, 0, "test");
            Add a defined cell to the worksheet
            Sheet.addcell (Templabel);
Jsoup Content Matching
    Document doc = Jsoup
                    . Connect (URL)
                    . Cookie ("Phpsessid", "prl7rupp8fud19iil04qod1886")
                    . Cookie ("token", "92a63634-e8b1-49db-acbf-4fac2bfcf44a")
                    . Cookies ("account_id", "173057768"). Timeout (30000). get ();

Processing of document
 Elements es = Doc.select ("div.qa_list > Div.qa_item");
                            if (es.size () > 0) {for (int j = 0; J < Es.size (); j + +) {String s = es
                            . Get (j). Select ("div.qa_question_list > Div.qa_question > Input") . attr ("value")//property value in Content + "---" + es.ge
                                    T (j). Select ("DIV.QA_ANSWER_BG > Div.qa_answer")
                The text value WriteToFile (file, S, append) in the label. }
            }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.