あなたがタイトルに惹かれていても私をscりません。
これは単なる実装であり、お気に入りの小説をダウンロードするためにさりげなく書いています。この例の小説は単なる例であり、私の料理ではありません。
JSOUPが使用されました。非常に便利なツール。
必要に応じて、それを参照して自分で変更してください。非常に簡単ですよね?
コードは次のとおりです。
パッケージ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(); }} / ** * nobleファイルにコンテンツを追加 * @param txtfile * noble file * @throws ioexception * @throws Internedexception * / private static void addcontent(file txtfile)throws ioexception、interrupedexception {appendtxt(txtfile、getbookinfo( "Infinite collaps"); 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();続く; }}} / ** * bookタイトルと著者 * @param bookname * book title * @param著者 * @return * / private static string getbookinfo(string bookname、string著者){return common.replace( "{book}"、bookname).replace( "{著者}"、著者); } / ** *ページコンテンツの読み取り * @param url *アクセスパス * @return * @throws ioexception * / private static string getPageContent(string url)throws ioexception {string rtn = null; document doc = jsoup.connect(url).get();要素コンテンツ= doc.select( "。テキストP");要素タイトル= doc.select( "#title"); system.out.println(title.text()); content.select( "font")。remove(); content.select( "script")。remaid(); content.select( "ins")。remove(); content.select( "a")。remove(); rtn = title.text() + newline + content.html()。lateall( "<p>"、 "").replaceall( "</p>"、 "").ReplaceAll( "/// newline Rtn; txtfile * @paramコンテンツ * @throws ioexception */ private void appledtxt(string content) / ** Line Breaks* / static final string newline = system.getProperty( "line.separator"); "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------上記は、編集者が提起した新しいコレクションプログラムのJava実装の簡単な例の完全な内容です。誰もがwulin.comをもっとサポートすることを願っています〜