web-harvest 是啥就不做介绍了,采集火影漫画的里面有下载链接。
http://blog.csdn.net/wind_324/article/details/6271412
样例抓取的是郭敬明的《1995-2005夏至未至》,简单看了下其他书籍的格式,基本上可以通用采集book.qq.com(未测试)。
废话少说,下面看配置文件。
<?xml version="1.0" encoding="GB2312"?> <!-- Extract novel "Rush to the Dead Summer,1995-2005" from book.qq.com) --> <config charset="GB2312"> <!-- 1. Init variables. --> <var-def name="baseUrl"><template>http://book.qq.com/s/book/0/5/5348/</template></var-def> <var-def name="maxloops">111</var-def> <!--<var-def name="nextXPath">//div[@id='TextInfo']/div[@id='pageList']/a[2]/@href</var-def>--> <var-def name="itemXPath">//div[@id='content']/text()</var-def> <var-def name="chapterTitle">//div[@id='TextInfo']/h1/text()</var-def> <!-- 2. Start to extract content of each chapter from web page. --> <while condition="${baseUrl.toString().length() != 0}" maxloops="${maxloops}" index="i"> <!-- Set variable pageUrl with new value. --> <var-def name="pageUrl"> <!-- <template>${nextLinkUrl.toString()}</template> --> <template>${baseUrl.toString()}${i}.shtml</template> </var-def> <empty> <!-- Crawl content from pageUrl. --> <var-def name="content"> <!-- omitunknowntags="true" --> <html-to-xml outputtype="pretty" specialentities="true" omitcomments="true" treatunknowntagsascontent="true" prunetags="head,script,style,select,li,table,form,br"> <http url="${pageUrl}" /> </html-to-xml> </var-def> <!-- Analyze & get the next link URL. --> <!-- <var-def name="nextLinkUrl"> <xpath expression="${nextXPath}"> <var name="content" /> </xpath> </var-def> --> <var-def name="title"> <xpath expression="${chapterTitle}"> <var name="content" /> </xpath> </var-def> <!-- Extract content of chapter from current page. --> <var-def name="chapterContent"> <xpath expression="${itemXPath}"> <script return="n_content.toString()"><![CDATA[ n_content = content.toString().trim().replace("\t","").replace("。 ","。\r\n"); //content = content.replace("<br />","\r\n"); ]]></script> </xpath> </var-def> <!-- output to txt files --> <file action="write" type="String" path="E:/Books/Rush_to_the_Dead_Summer_1995-2005/${title.toString()}.txt"> <template>${title.toString().trim()} ${sys.lf} ${chapterContent.toString().trim()} ${sys.lf} ${sys.lf} Extracted from : ${pageUrl.toString()} </template> </file> <!-- debug --> <!--<file action="write" type="String" path="E:/Books/Rush_to_the_Dead_Summer_1995-2005/page_${i}.xml"> <template>${content.toString()}</template> </file>--> </empty> </while> </config>
程序执行时间:INFO - Configuration executed in 47166ms. 也就是48秒下完一部111章的小说,速度还算理想。
下面是结果截图
此小说下载,请转至http://download.csdn.net/detail/wind_324/4029527
执行时间:INFO - Configuration executed in 47166ms. 也就是不到48秒,采集111章的小说,速度还算理想。
放到手机上简单看了一下,还是可以阅读的。但是在电脑上TXT打开的时候没有排版格式,但是editplus就可以看到排版,马上要放假了,暂时就这么出炉吧,欢迎留言讨论。
另:此文仅作学习参考使用,另使用或修改使用作其他用途概与本文作者无关。