Jangan memarahi saya jika Anda tertarik dengan judulnya.
Ini hanya implementasi sederhana, saya menulisnya dengan santai untuk mengunduh novel favorit. Novel dalam contoh hanyalah sebuah contoh, bukan hidangan saya.
Jsoup digunakan. Alat yang sangat berguna.
Jika perlu, silakan merujuk dan memodifikasinya sendiri. Cukup sederhana, bukan?
Kodenya adalah sebagai berikut:
Paket com.zhyea.doggie; impor java.io.file; impor java.io.filewriter; impor java.io.ioException; impor org.jsoup.jsoup; impor org.jsoup.nodes.document; impor org.jsoup.select.elements; kelas publik doggie {public static void main (string [] args) {coba {file txtfile = file baru ("d:/tak terbatas crash.txt"); createTxtDoc (txtfile); addContent (txtfile); } catch (Exception e) {E.PrintStackTrace (); } } /** * Add content to the novel file* @param txtFile * Novel file* @throws IOException * @throws InterruptedException */ private static void addContent(File txtFile) throws IOException, InterruptedException{ appendTxt(txtFile, getBookInfo("Infinite Collapse", "Spa Pa Pa Madman")); String url = "http://www.83kxs.com/view/12/12653/{pattern}.html"; untuk (int i = 5850686; i <= 5945501; i ++) {coba {string tmp = url.replace ("{pola}", i+"); appendtxt (txtfile, getPageContent (tmp)); } catch (Exception e) {E.PrintStackTrace (); melanjutkan; }}} / ** * Setel judul buku dan penulis * @param bookname * judul buku * @param penulis * penulis * @return * / private string getBookInfo (string bookname, string worhor) {return common.replace ("{book}", bookname) .replace ("{author}," {book}, bookname) .replace ("{" {"{" {"{{book {Book}. } / ** * Baca konten halaman * @param URL * Path Access * @return * @throws IoException * / Private Static String getPageContent (String URL) melempar IoException {String rtn = null; Dokumen doc = jsoup.connect (url) .get (); Elemen konten = doc.select (". Text p"); Elemen judul = doc.select ("#title"); System.out.println (title.text ()); Content.Select ("Font"). Remove (); Content.Select ("Script"). Remove (); content.Select ("INS"). Remove (); Content.Select ("A"). Remove (); rtn = title.text () + newline + content.html (). Replaceall ("<p>", "") .replaceall ("</p>", "") .replaceall ("//< !--(.+)-"). "" "" "" "" "" "" "" "" "" "" " Newline; @param txtfile * file txt untuk beroperasi * @param konten * untuk ditambahkan * @throws ioException */ private static void appendTxt (file txtfile, konten string) lemparan ioException {fileWriter writer = null (cobalah {writer = new fileWriter (txtFile, true); if (null! = writer) writer.close ();}} / *** Line breaks* / static final string newline = System.getProperty ("line.separator"); "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Di atas adalah konten lengkap dari contoh sederhana implementasi Java dari program pengumpulan baru yang dibawa kepada Anda oleh editor. Saya harap semua orang akan mendukung wulin.com lebih banyak ~