1 Star 0 Fork 192

幽烛 / PythonClimbInsect

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
downloadbook.py 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
振长策而御宇内 提交于 2014-01-15 09:32 . 修改的
# -*- coding:utf8 -*-
import urllib2,re
from bs4 import BeautifulSoup
root = 'http://www.biquge.com/'
urlList = [];
chaptername = raw_input('请输入笔趣阁小说章节目录子地址:')
print u"正在解析章节列表..."
soup = BeautifulSoup(urllib2.urlopen(root+chaptername+u'/').read())
novelname = soup.find('div',id='info').find('h1').get_text()
for result in soup.find(id="list").find("dt").find_next("dt").find_next_siblings("dd"):
res = result.find_next("a")
urlList.append(res['href'])
fileHandle = open(novelname+u'.txt','a')
for result in urlList:
temp = BeautifulSoup(urllib2.urlopen(root+result).read())
#print temp.find(id="content").get_text()
print u"正在下载:"+temp.title.text;
content = temp.find(id="content").get_text().encode('gbk','ignore')
#rstr = r'<(S*?)[^>]*>.*?|<.*? /> '
#fileHandle.write(re.sub(rstr, "", content))
fileHandle.write(content)
fileHandle.close()
print "~~~~~~~~~~~~~~~~~~~~~~~~~~END~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
#为了避免双击的时候直接一闪退出,在最后面加了这么一句
raw_input("Press <Enter> To Quit!")
1
https://gitee.com/liangzhiqian310/PythonClimbInsect.git
git@gitee.com:liangzhiqian310/PythonClimbInsect.git
liangzhiqian310
PythonClimbInsect
PythonClimbInsect
master

搜索帮助