python 爬虫入门之爬小说
##第一步 导包
from bs4 import BeautifulSoup
import requests
import sys ##准备
class downloder(object):
def __init__(self):
self.server = 'http://www.biqukan.com'
self.target = 'http://www.biqukan.com/1_1094/'
self.names = [] #存放章节名字
self.urls = [] #存放章节链接
self.nums = 0 # 章节数量
def get_download_url(self):
req = requests.get(url=self.target)
html = req.text
div_bf = BeautifulSoup(html)
div = div_bf.find_all('div',class_='listmain')
a_bf = BeautifulSoup(str(div[0]))
a = a_bf.find_all('a')
self.nums = len(a[15:])
for eatch in a[15:]:
self.names.append(eatch.string)
self.urls.append(self.server +eatch.get('href'))
def writer(self ,name,path,text):
write_flag = True
with open(path,'a',encoding='utf-8') as f:
f.write(name +'\n')
f.writelines(text)
f.writelines('\n\n')
def get_contents(self,target):
req = requests.get(url=target)
html = req.text
bf = BeautifulSoup(html)
texts = bf.find_all('div',class_ = 'showtxt')
texts = texts[0].text.replace( '\xa0'*8,'\n\n')
return texts if __name__ == '__main__':
dl = downloder()
dl.get_download_url()
print('开始下载')
for i in range(dl.nums):
dl.writer(dl.names[i],'用点.txt',dl.get_contents(dl.urls[i]))
print("下载完成") 参考华哥的内容... 还有好多不懂
http://cuijiahua.com/blog/2017/10/spider_tutorial_1.html
python 爬虫入门之爬小说的更多相关文章
- Python 爬虫入门之爬取妹子图
Python 爬虫入门之爬取妹子图 来源:李英杰 链接: https://segmentfault.com/a/1190000015798452 听说你写代码没动力?本文就给你动力,爬取妹子图.如果 ...
- Python 爬虫入门(二)——爬取妹子图
Python 爬虫入门 听说你写代码没动力?本文就给你动力,爬取妹子图.如果这也没动力那就没救了. GitHub 地址: https://github.com/injetlee/Python/blob ...
- python 爬虫入门----案例爬取上海租房图片
前言 对于一个net开发这爬虫真真的以前没有写过.这段时间学习python爬虫,今天周末无聊写了一段代码爬取上海租房图片,其实很简短就是利用爬虫的第三方库Requests与BeautifulSoup. ...
- python 爬虫入门案例----爬取某站上海租房图片
前言 对于一个net开发这爬虫真真的以前没有写过.这段时间开始学习python爬虫,今天周末无聊写了一段代码爬取上海租房图片,其实很简短就是利用爬虫的第三方库Requests与BeautifulSou ...
- Python 爬虫入门(一)——爬取糗百
爬取糗百内容 GitHub 代码地址https://github.com/injetlee/Python/blob/master/qiubai_crawer.py 微信公众号:[智能制造专栏],欢迎关 ...
- Python爬虫入门:爬取pixiv
终于想开始爬自己想爬的网站了.于是就试着爬P站试试手. 我爬的图的目标网址是: http://www.pixiv.net/search.php?word=%E5%9B%9B%E6%9C%88%E3%8 ...
- Python爬虫入门:爬取豆瓣电影TOP250
一个很简单的爬虫. 从这里学习的,解释的挺好的:https://xlzd.me/2015/12/16/python-crawler-03 分享写这个代码用到了的学习的链接: BeautifulSoup ...
- python 爬虫入门1 爬取代理服务器网址
刚学,只会一点正则,还只能爬1页..以后还会加入测试 #coding:utf-8 import urllib import urllib2 import re #抓取代理服务器地址 Key = 1 u ...
- python - 爬虫入门练习 爬取链家网二手房信息
import requests from bs4 import BeautifulSoup import sqlite3 conn = sqlite3.connect("test.db&qu ...
随机推荐
- mybatis使用foreach进行批量插入和删除操作
一.批量插入 1.mapper层 int insertBatchRoleUser(@Param("lists") List<RoleUser> lists);//@Pa ...
- android studio升级方法
android studio 更新问题: 如果被墙则采用以下步骤: 一:看版本 help-->about AI***************** 二:查看android studio最新版 ...
- 多因子降维法(MDR,Multifactor Dimensionality Reduction )
多因子降维法(MDR,multifactor dimensionality reduction) 多因子降维法(MDR,Multifactor Dimensionality Reduction ) ...
- 判断字符串是否为回文 python
回文正序和逆序一样的字符串,例如abccba 方法一 def is_palindrome1(text): l = list(text) l.reverse() t1 = ''.join(l) if t ...
- Android JIN简单单步调试
ADTr20已经比较完美支持NDK开发了.可以集成ndk编译,只需在项目右键Add Native Support,就能自动生成jni文件,并部署编译环境(注意这个过程是不可逆的,手动删除jni文件后, ...
- checkbox数据回显问题
一.问题 在用复选框的时候,最常用的无非就是全选,全不选,数据回显等问题!要做的比较灵活!最近做项目的时候,就遇到这些问题,下面从js和JQueyr两方面解决一下全选,全不选,数据回显的问题. 二.H ...
- 如何用word文档在博客里发表文章
目前大部分的博客作者在用Word写博客这件事情上都会遇到以下3个痛点: 1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.使用Word写 ...
- B-spline Curves 学习之B样条基函数计算实例(3)
B-spline Basis Functions: Computation Examples 本博客转自前人的博客的翻译版本,前几章节是原来博主的翻译内容,但是后续章节博主不在提供翻译,后续章节我在完 ...
- Web Service Error wsse:InvalidSecurity Policy Requires Integrity (Doc ID 1370736.1)
Web Service Error wsse:InvalidSecurity Policy Requires Integrity (Doc ID 1370736.1) Modified: 13 ...
- JavaScript中的垃圾回收和内存泄漏
摘要: JS内存管理. 作者:浪里行舟 Fundebug经授权转载,版权归原作者所有. 前言 程序的运行需要内存.只要程序提出要求,操作系统或者运行时就必须供给内存.所谓的内存泄漏简单来说是不再用到的 ...