Don't scold me if you are attracted by the title.
It's just a simple implementation, I wrote it casually to download a favorite novel. The novel in the example is just an example, not my dish.
jsoup was used. Very useful tool.
If necessary, please refer to it and modify it yourself. Quite simple, right?
The code is as follows:
package com.zhyea.doggie;import java.io.File;import java.io.FileWriter;import java.io.IOException;import org.jsoup.Jsoup;import org.jsoup.nodes.Document; import org.jsoup.select.Elements;public class Doggie { public static void main(String[] args){ try{ File txtFile = new File("D:/Infinite 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"; for(int i=5850686; i<=5945501; i++){ try{ String tmp = url.replace("{pattern}", i+""); appendTxt(txtFile, getPageContent(tmp)); }catch(Exception e){ e.printStackTrace(); continue; } } } /** * Set the book title and author* @param bookName * Book title* @param author * Author * @return */ private static String getBookInfo(String bookName, String author){ return COMMON.replace("{book}", bookName).replace("{author}", author); } /** * Read page content* @param url * Access path* @return * @throws IOException */ private static String getPageContent(String url) throws IOException{ String rtn = null; Document doc = Jsoup.connect(url).get(); Elements content = doc.select(".text p"); Elements title = 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("//<!--(.+)--//////////// .replaceAll("", "") .replaceAll("<br>", NEWLINE) + NEWLINE; return rtn; } /** * Create a new txt file* @param fullName * Full name of the file* @return * @throws Exception */ private static boolean createTxtDoc(File txtFile) throws Exception{ try{ return txtFile.createNewFile(); }catch(Exception e){ throw e; } } /** * Append content to the txt file* @param txtFile * txt file to operate* @param content * Content to be appended* @throws IOException */ private static void appendTxt(File txtFile, String content) throws IOException{ FileWriter writer = null; try{ writer = new FileWriter(txtFile, true); writer.append(content); } finally{ if(null!=writer)writer.close(); } } /** * Line breaks*/ static final String NEWLINE = System.getProperty("line.separator"); /** * General information before the book*/ static String COMMON = "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------The above is the full content of the simple example of Java implementation of a novel collection program brought to you by the editor. I hope everyone will support Wulin.com more~