抓取biqukan
#python3.7
'''
功能:实现www.biqukan.com/1_1094/5403177.html小说下载为txt
v1.0
'''
import requests,sys,time
from lxml import etree
##0.获取所有章节url
def get_url_list(catalog_url):
res=requests.get(catalog_url)
#time.sleep(1)
if res.status_code==200:
text=res.text
html=etree.HTML(text)
hrefs=html.xpath('//div[@class="listmain"]/dl/dt[2]/following-sibling::*/a/@href')
#print('hrefs')
return hrefs
return None ##1.获取页面
def get_one_page(url):
res=requests.get(url)
#time.sleep(1)
if res.status_code==200:
return res.text
return None ##2.解析页面
def parse_one_page(text):
html=etree.HTML(text)
title=html.xpath('//div[@class="content"]/h1//text()')
content=html.xpath('//div[@class="showtxt"]//text()') #去掉换行
contents=''.join(content).replace('\xa0'*8,'\n'*2)#把列表转换为一整段文本,并把8个空格换为2个换行
#print(title,contents) #print(title)
return title,contents #返回多个参数,相当于返回一个元组return(title,content) ##3.保存内面
def write_to_file(title,contents):
with open('一念永恒.txt','a',encoding='utf-8')as f:
f.write(title[0]+'\n'+contents+'\n') #for content in contents:
# f.write(content) ##主函数
def main():
#0.获取章节列表的网址
catalog_url='https://www.biqukan.com/1_1094/'
urls=get_url_list(catalog_url)
#print(urls)
#1.把网址传入详情抓取页面,并保存
for i in range(len(urls)):
rel_url='https://www.biqukan.com'+urls[i]
print(rel_url)
text=get_one_page(rel_url)
#接收2步return的多个参数写法a,b=(x,y)
title,contents=parse_one_page(text)
#print(title,contents)
#写入txt
write_to_file(title[0],contents)
#显示下载进度
sys.stdout.write(" 已下载:%.3f%%" % float(i/len(urls)) + '\r')
sys.stdout.flush() ##执行入口
if __name__=='__main__':
main()
抓取biqukan的更多相关文章
- 【爬虫】biqukan抓取2.0版
#!python3.7 import requests,sys,time,logging,random from lxml import etree logging.basicConfig(level ...
- 笔趣看小说Python3爬虫抓取
笔趣看小说Python3爬虫抓取 获取HTML信息 解析HTML信息 整合代码 获取HTML信息 # -*- coding:UTF-8 -*- import requests if __name__ ...
- 用WebRequest +HtmlAgilityPack 从外网抓取数据到本地
相信大家对于WebRequest 并不陌生,我们在C#中发请求的方式,就是创建一个WebRequest .那么如果我们想发一个请求到外网,比如国内上不了的一些网站,那么该怎么做呢? 其实WebRequ ...
- Phantomjs+Nodejs+Mysql数据抓取(2.抓取图片)
概要 这篇博客是在上一篇博客Phantomjs+Nodejs+Mysql数据抓取(1.抓取数据) http://blog.csdn.net/jokerkon/article/details/50868 ...
- [转]Fiddler抓取Android真机上的HTTPS包
此篇文章转载自:http://blog.csdn.net/roland_sun/article/details/30078353 工作中经常会需要对一些app进行抓包, 但是每次默认都是只抓http请 ...
- 爬虫技术 -- 进阶学习(十)网易新闻页面信息抓取(htmlagilitypack搭配scrapysharp)
最近在弄网页爬虫这方面的,上网看到关于htmlagilitypack搭配scrapysharp的文章,于是决定试一试~ 于是到https://www.nuget.org/packages/Scrapy ...
- Phantomjs+Nodejs+Mysql数据抓取(1.数据抓取)
概要: 这篇博文主要讲一下如何使用Phantomjs进行数据抓取,这里面抓的网站是太平洋电脑网估价的内容.主要是对电脑笔记本以及他们的属性进行抓取,然后在使用nodejs进行下载图片和插入数据库操作. ...
- 网络爬虫:使用Scrapy框架编写一个抓取书籍信息的爬虫服务
上周学习了BeautifulSoup的基础知识并用它完成了一个网络爬虫( 使用Beautiful Soup编写一个爬虫 系列随笔汇总 ), BeautifulSoup是一个非常流行的Python网 ...
- 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(3): 抓取amazon.com价格
通过上一篇随笔的处理,我们已经拿到了书的书名和ISBN码.(网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(2): 抓取allitebooks.com书籍信息 ...
随机推荐
- 跨域的问题(nginx解决才是王道)
跨域分为两类:一时get跨域,而是post跨域.常见的是三种: 一种是jsonp, $.ajax({ url: "http://127.0.0.1/~chenjiebin/mycode/ph ...
- css权重计算规则
1.第一等:代表内联样式,如 style=" ",权值为1000: 2.第二等:代表ID选择器,如 #content,权值为0100: 3.第三等:代表类,伪类和属性选择器,如 . ...
- 【托业】【全真题库】TEST01-03-阅读题
[托业][全真题库]TEST01-03-阅读题
- thinkphp无法安装提示修改mysql配置
在安装以thinkphp为框架的系统时数据库连接错误,提示修改sql-mode或sql_mode为NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION.那我们就顺着提示 ...
- 报错解决——make: *** No targets specified and no makefile found. Stop
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz tar zxvf ncurses-5.6.tar.gz #切换目录到ncurses ...
- personalblog
personalBlog loginRegist页面结构 <div class="navbar-collapse nostyle collapse clearfix"> ...
- vue-element分页
<template> <card-layout :title="L('Users')" :actions="actions" @click=& ...
- 【LeetCode每天一题】Two Sum(两数之和)
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- MongoDB--预备
- Linux配置eclipse实践
有几年没有在Linux下用eclipse开发了,几年前是在CentOS 7下用eclipse开发的,好像用的还是较新的版本.最近有个项目要求在centos 下卡发,装上eclipse-cdt后,建立项 ...