博客
关于我
Python 爬取起点的小说(非vip)
阅读量:357 次
发布时间:2019-03-04

本文共 738 字,大约阅读时间需要 2 分钟。

                  Python 爬取起点的小说(非vip)

起点小说网是一个小说种类比较全面的网站,当然,作为收费类网站,VIP类的小说也很多,章节是VIP的话,有一个动态加载,也就是ajax,需要抓包分析网址,由于我没有VIP账号,所以只能爬取非VIP章节,这个爬虫就以爬取一部小说 冒牌大英雄为例,首先,我们可以打开冒牌大英雄所在的网址,也就是 以 这个网址为起点,依次取出各个章节的网址,在取出网址的同时,选取文章的标题和内容,写入本地硬盘,每一个章节为一个文件,保存格式为html格式,技术选型方面,使用第三方库requests。

爬取流程:起始网址 的网页源代码内带有所有章节的链接网址,首先,解析起始网址,取得起始网址源代码,编写正则提取章节链接,然后循环读取章节链接,正则提取标题和内容,每次循环,将标题加时间戳设为文件名称,内容写入文件中,爬虫就算结束了。下面。上代码:

import timeimport requestsimport reurl='https://book.qidian.com/info/131957'headers = {    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',    'accept-encoding': 'gzip, deflate, sdch, br',    'accept-language': 'zh-CN,zh;q=0.8'}data=requests.get(url,headers=headers).textpat=' 
  •  

    转载地址:http://kokr.baihongyu.com/

    你可能感兴趣的文章
    Nginx+Keepalived实现简单版高可用主备切换
    查看>>
    Nginx+Lua 开发高性能Web应用实战
    查看>>
    nginx+mysql+redis+mongdb+rabbitmq 自动化部署脚本
    查看>>
    nginx+php的搭建
    查看>>
    Nginx+Redis+Ehcache:大型高并发与高可用的三层缓存架构总结
    查看>>
    nginx+tomcat+memcached
    查看>>
    nginx+tomcat单个域名及多个域名配置
    查看>>
    Nginx+Tomcat实现动静分离
    查看>>
    nginx+Tomcat性能监控
    查看>>
    nginx+uwsgi+django
    查看>>
    nginx+vsftp搭建图片服务器
    查看>>
    Nginx-http-flv-module流媒体服务器搭建+模拟推流+flv.js在前端html和Vue中播放HTTP-FLV视频流
    查看>>
    nginx-vts + prometheus 监控nginx
    查看>>
    Nginx/Apache反向代理
    查看>>
    Nginx: 413 – Request Entity Too Large Error and Solution
    查看>>
    nginx: [emerg] getpwnam(“www”) failed 错误处理方法
    查看>>
    nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:
    查看>>
    nginx: [error] open() “/usr/local/nginx/logs/nginx.pid“ failed (2: No such file or directory)
    查看>>
    nginx:Error ./configure: error: the HTTP rewrite module requires the PCRE library
    查看>>
    Nginx:objs/Makefile:432: recipe for target ‘objs/src/core/ngx_murmurhash.o‘解决方法
    查看>>