7

Python爬虫编程思想(36):项目实战-抓取斗破小说网的目录和全文

 2 years ago
source link: https://blog.csdn.net/nokiaguy/article/details/120541383
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Python爬虫编程思想(36):项目实战-抓取斗破小说网的目录和全文

专栏收录该内容
36 篇文章 2 订阅 ¥29.90 ¥99.00

        到现在为止我们已经学习了3个Python网络库(urllib、urllib3和requests),以及通过正则表达式过滤字符串。现在该来点实战了。本节以及后面2节会给出3个案例,分别使用urllib、urllib3以及requests,并通过正则表达式抓取Web数据,这些数据或者显示在Console中,或者保存到文本文件中。

        本文要实现的案例是通过urllib库抓取斗破小说网(http://www.doupoxs.com)上指定的小说的目录和每一节的完整内容(只保留纯文本内容)。当抓取包含目录和小说内容的页面后,会通过正则表达式分析HTML代码,并提取出目录标题、对应的URL以及文本形式的小说内容。

        现在进入斗破小说网,选择一篇小说,本节选择了http://www.doupoxs.com/nalanwudi,目录页面如图1所示。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK