当前位置:编程学习 > 网站相关 >>

python之小说下载器version3.0

 我想了一下,每个版本打包exe 意义不大,如果是最终版什么的 打一个还行,所以暂时不打包了 有需要的可以留言,我在打包.

        这里使用了第三方库pyquery,安装方法见:1.0版本链接

        在上一版本的基础上做个改进.主要是,增加推荐榜,支持模糊查询,交互方式有一定优化.如上图:

 

 \\
 

 

        下面是代码:


[python] 
# -*- coding:gbk -*-  
'''''
file desc:novel downloader
author:kingviker
email:kingviker@163.com.kingviker88@gmail.com
date:2013-05-21
depends:python 2.7.4,pyquery
''' 
 
import os,codecs,urllib,urllib2,sys 
from pyquery import PyQuery as pq 
 
 
   
searchUrl = 'http://www.dushuge.net/modules/article/search.php'     
baseSavePath="E:/enovel/" 
   
def searchTopList(): 
    html = pq(url="http://www.dushuge.net") 
    searchTopA= html("#compZnNav").next().find("td").eq(0)("a") 
    searchTopList = [] 
    for index in range(1,len(searchTopA)): 
        searchTopList.append([searchTopA.eq(index).text(),searchTopA.eq(index).attr("href")]) 
    return  searchTopList 
 
def searchNovel(novelName): 
     
  
 
    values = urllib.urlencode({'searchkey' : novelName,     
              'searchtype' : 'articlename'}) 
    req = urllib2.Request(url=searchUrl,data=values) 
    response = urllib2.urlopen(req) 
    searchHtml_pq = pq(response.read()) 
 
    novelUrlHtml = searchHtml_pq("#content > .sf-mainbox > .head > h1 > a") 
    #print novelUrlHtml  
    if not novelUrlHtml : 
        resultList = searchHtml_pq("#content > table > tr") 
        if resultList: 
            novelList = []     
            for index in range(1,len(resultList)): 
                novelTR = resultList.eq(index) 
                novelA = novelTR("td").eq(0)("a") 
                #print novelA.text(),novelA.attr("href")  
                novelList.append([novelA.text(),novelA.attr("href")]) 
            return novelList 
        else: 
            return 
    return (novelUrlHtml.eq(2).text(),novelUrlHtml.eq(2).attr("href")) 
 
def analyzeNovel(url): 
    print "开始分析章节信息..." 
    #using pyquery to grub the webpage's content  
    html_pq = pq(url=url) 
    #print html_pq("div.book_article_texttable").find(".book_article_texttext")  
    totalChapters = len(html_pq("div.book_article_texttable").find(".book_article_listtext").find("a")) 
    print "总章节数:",totalChapters 
    return totalChapters 
 
def fetchDownloadLinks(url): 
    #using to save pieces and chapter lists  
    pieceList=[] 
    chapterList=[] 
 
    html_pq = pq(url=url) 
    #find the first piece of the novel.  
    piece = html_pq("div.book_article_texttable > div").eq(0) 
 
    isPiece = True 
    if piece.attr("class")=="book_article_texttitle": 
        #get the current piece's text  
        pieceList.append(piece.text()) 
        #print "piece Text:", piece  
    else: 
        isPiece = False 
        pieceList.append("无") 
    #scan out the piece and chapter lists  
    nextPiece=False 
    while nextPiece==False: 
        if isPiece: 
            chapterDiv = piece.next() 
        else: 
            isPiece = True 
            chapterDiv = piece 
        #print "章节div长度:",chapterDiv.length  
        piece = chapterDiv 
        if chapterDiv.length==0: 
            pieceList.append(chapterList[:]) 
            del chapterList[:] 
            nextPiece=True 
        elif chapterDiv.attr("class")=="book_article_texttitle": 
            pieceList.append(chapterList[:]) 
            del chapterList[:] 
            pieceList.append(piece.text()) 
         
        else: 
            chapterUrls = chapterDiv.find("a"); 
         &

补充:Web开发 , Python ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,