网络爬虫爬取小说3
2017-02-07 16:47
176 查看
from urllib import request from bs4 import BeautifulSoup import re def 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_doc def getTitle(soup): return soup.title.string def 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的使用,欢迎指教(野路子)
相关文章推荐
- java网络爬虫-爬取小说
- Python爬虫入门实战系列(一)--爬取网络小说并存放至txt文件
- 爬虫之窃取网络小说(1)-yellowcong
- Python网络爬虫——我的第二个爬虫(爬取小说信息)
- Python网络爬虫——我的第二个爬虫(爬取小说信息)
- 基于JSoup的网络爬虫爬取小说内容
- 基于Java的网络爬虫实现抓取网络小说(一)
- python 爬虫 网络小说下载(静态网站)
- Python 网络爬虫之 百度贴吧原创小说
- 爬虫之窃取网络小说(2,多线程爬虫)-yellowcong
- C#网络爬虫抓取小说
- 第一个简单爬虫之下载盗版网络小说
- 爬虫练习-爬取小说
- Apache2.4使用require指令进行访问控制--允许或限制IP访问/通过User-Agent禁止不友好网络爬虫
- [Python]网络爬虫学习笔记,爬取豆瓣妹子上妹子的照片
- JAVA平台上的网络爬虫脚本语言 CrawlScript
- 网络爬虫
- 网络爬虫入门
- 网络爬虫基本原理(二)
- python网络爬虫(一):网络爬虫科普与URL含义