제목에 매료되면 나를 꾸짖지 마십시오.
단순한 구현 일뿐입니다. 나는 좋아하는 소설을 다운로드하기 위해 우연히 썼습니다. 이 예제의 소설은 단지 내 요리가 아닌 예일뿐입니다.
JSOUP가 사용되었습니다. 매우 유용한 도구.
필요한 경우 참조하여 직접 수정하십시오. 아주 간단합니까?
코드는 다음과 같습니다.
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 (예외 e) {e.printstacktrace (); }} / ** * 소설 파일에 컨텐츠 추가 * @param txtfile * 소설 파일 * @throws ioexception * @throws InterruptedException * / private static void addcontent (파일 txtfile)는 ioexception, InterruptedTxt (txtfile, getBookInfo ")))) 문자열 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 (예외 e) {e.printstacktrace (); 계속하다; }}} / ** * 책 제목과 저자 설정 * @param bookname * 책 제목 * @param 저자 * @return * / private static string getBookInfo (String BookName, String aworuge) {return common.replace ( "{book}", BookName) .replace ( "{{author}", Author); } / ** * 페이지 내용 읽기 * @param url * 액세스 경로 * @return * @throws ioexception * / private static string getPageContent (String URL)는 ioException {String rtn = null; 문서 doc = jsoup.connect (url) .get (); 요소 내용 = doc.Select ( ". 텍스트 p"); 요소 제목 = doc.select ( "#title"); System.out.println (title.text ()); content.select ( "font"). remove (); content.select ( "스크립트"). remove (); content.select ( "ins"). 제거 (); content.select ( "a"). 제거 (); rtn = title.text () + newline + content.html (). replaceall ( "<p>", "") .replaceall ( "</p>", "") .replaceall ( "//<! rtn; * @param 컨텐츠 * @Throws IOException */ private static void appendtxt (filewriter = null). }} / *** 라인 브레이크* / 정적 최종 문자열 newline = system.getProperty ( "line.separator"); "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------위의 것은 편집자가 제공 한 소설 컬렉션 프로그램의 Java 구현의 간단한 예제의 전체 내용입니다. 모두가 wulin.com을 더 지원하기를 바랍니다