最近想看盗墓笔记,看了一下网页代码,竟然不是js防爬虫,那就用简单的代码爬下了一节:

"""
爬取盗墓笔记小说-七星鲁王宫
""" from urllib.request import urlopen
from bs4 import BeautifulSoup
from docx import Document
import os class Download(): def __init__(self):
self.baseUrl = 'http://www.daomubiji.com/nu-hai-qian-sha-'
self.basePath = os.path.dirname(__file__) def makedir(self, name):
path = os.path.join(self.basePath, name)
isExist = os.path.exists(path)
if not isExist:
os.makedirs(path)
print('File has been created.')
else:
print('The file is existed.')
#切换到该目录下
os.chdir(path) def connect(self, url):
try:
html = urlopen(url)
print(url)
obj = BeautifulSoup(html, 'lxml')
except:
print('This page is not existed.')
return obj def getContent(self):
doc = Document()
self.makedir('storyFiles')
for page in range(1,47):
if page < 10:
url = self.baseUrl + '' + str(page) + '.html'
else:
url = self.baseUrl + str(page) + '.html'
obj = self.connect(url)
content = obj.find('article', {'class': 'article-content'})
doc.add_paragraph(content.text)
doc.save('盗墓笔记-怒海潜沙.doc') if __name__ == '__main__':
obj = Download()
obj.getContent()

Python 爬虫-抓取小说《盗墓笔记-怒海潜沙》的更多相关文章

  1. Python 爬虫-抓取小说《鬼吹灯之精绝古城》

    想看小说<鬼吹灯之精绝古城>,可是网页版的好多广告,还要一页一页的翻,还无法复制,于是写了个小爬虫,保存到word里慢慢看. 代码如下: """ 爬取< ...

  2. python 爬虫抓取心得

    quanwei9958 转自 python 爬虫抓取心得分享 urllib.quote('要编码的字符串') 如果你要在url请求里面放入中文,对相应的中文进行编码的话,可以用: urllib.quo ...

  3. Python爬虫----抓取豆瓣电影Top250

    有了上次利用python爬虫抓取糗事百科的经验,这次自己动手写了个爬虫抓取豆瓣电影Top250的简要信息. 1.观察url 首先观察一下网址的结构 http://movie.douban.com/to ...

  4. Python爬虫抓取东方财富网股票数据并实现MySQL数据库存储

    Python爬虫可以说是好玩又好用了.现想利用Python爬取网页股票数据保存到本地csv数据文件中,同时想把股票数据保存到MySQL数据库中.需求有了,剩下的就是实现了. 在开始之前,保证已经安装好 ...

  5. C# 爬虫 抓取小说

    心血来潮,想研究下爬虫,爬点小说. 通过百度选择了个小说网站,随便找了一本小书http://www.23us.so/files/article/html/13/13655/index.html. 1. ...

  6. python爬虫抓取哈尔滨天气信息(静态爬虫)

    python 爬虫 爬取哈尔滨天气信息 - http://www.weather.com.cn/weather/101050101.shtml 环境: windows7 python3.4(pip i ...

  7. python爬虫——爬取小说 | 探索白子画和花千骨的爱恨情仇(转载)

    转载出处:药少敏   ,感谢原作者清晰的讲解思路! 下述代码是我通过自己互联网搜索和拜读完此篇文章之后写出的具有同样效果的爬虫代码: from bs4 import BeautifulSoup imp ...

  8. Python爬虫 -- 抓取电影天堂8分以上电影

    看了几天的python语法,还是应该写个东西练练手.刚好假期里面看电影,找不到很好的影片,于是有个想法,何不搞个爬虫把电影天堂里面8分以上的电影爬出来.做完花了两三个小时,撸了这么一个程序.反正蛮简单 ...

  9. Python 爬虫: 抓取花瓣网图片

    接触Python也好长时间了,一直没什么机会使用,没有机会那就自己创造机会!呐,就先从爬虫开始吧,抓点美女图片下来. 废话不多说了,讲讲我是怎么做的. 1. 分析网站 想要下载图片,只要知道图片的地址 ...

随机推荐

  1. 【hihocoder 1554】最短的 Nore0061

    [链接]http://hihocoder.com/problemset/problem/1554 [题意] 中文题 [题解] DP; 设f[i][j][k]表示前i个字符,第一个串已经得到了前j个字符 ...

  2. 其它课程中的python---5、Pandas处理数据和读取数据

    其它课程中的python---5.Pandas处理数据和读取数据 一.总结 一句话总结: 记常用和特例:慢慢慢慢的就熟了,不用太着急,慢慢来 库的使用都很简单:就是库的常用函数就这几个,后面用的时候学 ...

  3. error C2065: CoInitializeEx' : undeclared identifier 解决方法

    错误: error C2065: CoInitializeEx' : undeclared identifier 解决方法 原因: 本来程序的编译选项选择的是:使用标准windows库,当改为在静态库 ...

  4. Http协议中get和post的区别 转载https://www.cnblogs.com/lexiaofei/p/http.html

    get(默认值)是通过URL传递表单值,数据追加在action属性后面. post传递的表单值是隐藏到http报文体中,url中看不到. get是通过url传递表单值,post通过url看不到表单域的 ...

  5. Mysql DBA

    1 mysqldump: Error 2020: Got packet bigger than 'max_allowed_packet' bytes when dumping table `tb_co ...

  6. ICPC Asia Nanning 2017 L. Twice Equation (规律 高精度运算)

    题目链接:Twice Equation 比赛链接:ICPC Asia Nanning 2017 Description For given \(L\), find the smallest \(n\) ...

  7. 前端(十六)—— JavaScript盒子模型、JS动画、DOM、BOM

    JS盒子模型.JS动画.DOM.BOM 一.JS盒模型 1.width | height parseInt(getComputedStyle(ele, null).getPropertyValue(' ...

  8. Python 内置函数&filter()&map()&reduce()&sorted()

    常用内置函数 Python 2.x 返回列表,Python 3.x 返回迭代器 在进行筛选或映射时,输出的结果是一个数组,需要list帮助. 如:print(list(map(lambda x:x+1 ...

  9. 使用wireshark在windows平台下捕获HTTP协议数据包中的帐号密码信息

    1.打开wireshark软件,从Interface List中选择相应的网卡,例如我的PC机上是“本地连接”,然后选择”Start”启动抓包程序. 2.打开学校主页,输入账号和密码登录校内邮箱. 3 ...

  10. 上线出现[x86_64, i386]

    echo "Target architectures: $ARCHS" APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}&quo ...