网络爬虫爬取小说3
来源:互联网 发布:黄金软件哪个好 编辑:程序博客网 时间:2024/05/21 21:39
from urllib import requestfrom bs4 import BeautifulSoupimport redef getHtml(url ): page = request.urlopen(url) html_doc = page.read() html_doc = html_doc.replace(u'\xa0', u' ') html_doc = str(html_doc) html_doc = html_doc.replace("<br/>","\n") return html_docdef getTitle(soup): return soup.title.stringdef getContent(soup): return soup.find(id="content").get_text()def getNextURL(soup): next_init_url = str(soup.find(id="pager_next")) next_url = re.search("\d+\.html", next_init_url) if next_url is None: return False return next_url.group()def getBook(url,name): txt = '' book = open("./res/"+name,"w+") while bool(url): html_doc = getHtml(url) soup = BeautifulSoup(html_doc, 'html.parser') title = soup.title.string book_content = soup.find(id="content").get_text() book.write(title+book_content) if bool(getNextURL(soup)): url = re.sub("\d+.html", getNextURL(soup), url) else: break if not book.closed: book.close() print("ok")url = "http://www.biqulou.net/24/24835/7406090.html"# url = "http://www.biqulou.net/24/24835/14627850.html"getBook(url,"大主宰")
这个是对于第三方库BeautifulSoup的使用,欢迎指教(野路子)
0 0
- 网络爬虫爬取小说3
- java网络爬虫-爬取小说
- Python3网络爬虫(七):使用Beautiful Soup爬取小说
- Python3网络爬虫(二):使用Beautiful Soup爬取小说
- Python3网络爬虫:使用Beautiful Soup爬取小说
- 基于JSoup的网络爬虫爬取小说内容
- 爬虫第五战 scrapy小说爬取
- Python requests爬虫爬取小说数据
- Python爬虫——小说爬取
- python3.5爬虫完成笔趣阁小说的爬取
- Scala语言编写的爬虫应用-爬取一部小说
- Python爬虫实例--爬取百度贴吧小说
- Python爬虫系列:爬取小说并写入txt文件
- Python爬虫:爬取小说花千骨--转自微信
- C#网络爬虫抓取小说
- Python爬取小说
- 爬取起点小说
- python爬取小说
- 在CentOS最小化服务器版本中如何查找网卡IP和其它详细信息?
- java 验证码
- MYSQL相关
- poj 1265 Area
- poj 1611 The Suspects(并查集)
- 网络爬虫爬取小说3
- map的4中遍历方式
- TF-IDF权重计算:TfidfTransformer(),CountVectorizer()和TfidfVectorizer()
- Python 面试题 https://github.com/taizilongxu/interview_python
- 应用集成实战系列:集成应用的业务日志很重要
- java集合细节(二):asList的缺陷
- Shiro的使用与配置实战
- 傅里叶变换
- 库文件