这次爬虫并没有遇到什么难题,甚至没有加header和data就直接弄到了盗版网站上的小说,真是大大的幸运。
所用模块:urllib,re
主要分三个步骤:
(1)分析小说网址构成;
(2)获取网页,并分离出小说章节名和章节内容;
(3)写入txt文档。
#-*-coding:GBK-*-
#author:zwg
'''
爬取某小说网站的免费小说
'''
import urllib
import urllib2
import re
url='http://www.bxwx8.org/b/8/8987/2093383.html'
url1='http://www.bxwx8.org/b/8/8987/2093%d.html'
def gethtml(url):
page=urllib.urlopen(url)
html=page.read()
return html
def get_name_content(html):
re1=re.compile('<title>.+?</title>')
re2=re.compile('<div id="content"><div id="adright">.+?</div>')
s1=re1.findall(html)
s2=re2.findall(html)
if len(s1)>0 and len(s2)>0:
name=s1[0].replace('<tit