python3爬虫实战之小说(一)

Android 本地网络小说爬虫,基于 jsoup 及 xpath,Android入门教程 项目地址:smuyyh/CrawlerForReader  简介:Android 本地网络小说爬虫,基于 jsoup 及 xpath 更多:作者   提 Bug 标签: Android 本地网络小说爬虫,基于 jsoup 与 xpath,通过模版解析网页。 支持书源 模版示例 调用方式 ScreenShot 支持书源 /** 所有书源 */ public static final SparseArray SOURCES = new Spar. 阅读详情

一、目标
以前看过择天记,挺喜欢的,这次选它为目标
知乎:https://zhuanlan.zhihu.com/p/41282580
GitHub:https://github.com/FanShuixing/git_webspider

(ps:支持正版,本文纯属学习交流)
这里写图片描述

二、知识点
1、pyquery解析网页,相比较BeautifulSoup,我选择pyquery,pyquery在css选择上很是强大和方便,一会我们来感受一下

若是没有安装,直接pip3 install pyquery,同时推荐崔大的 https://cuiqingcai.com/5551.html

2、requests库的使用
如不熟悉可参考文档:http://docs.python-requests.org/zh_CN/latest/user/quickstart.html

三、进入正题
整体思路:先下载网页,并提取出这一页的标题和链接—>根据链接,抓取每一页的数据。

进入上图中的链接后,我们首先下载这个网页,并打印出来(ps:本文提供思路和方法,如requests和pyquery的详细介绍可参考知识点中罗列出来的网址)

import requests

def crawle():
    url='https://www.qtshu.com/zetianji/'
    req=requests.get(url=url)
    html=req.text
    print(html)


crawle()

输出如下图:这里写图片描述

编码不正确,使用encoding可以改变编码,首先我们需要知道网页采用的是什么编码,我们打开网页的开发者工具(F12),查看head标签下的信息
这里写图片描述
charset中的‘utf-8’就是网页的编码,改变编码

import requests

def crawle():
    url='https://www.qtshu.com/zetianji/'
    req=requests.get(url=url)
    req.encoding='utf-8'
    html=req.text
    print(html)


crawle()

这下网页就被正确的打印出来了。

只是单纯的下载网页没有什么意义,爬虫主要的目的是提取数据,接下来我们通过pyquery提取标题和链接,在任意一个标题下右键审查元素,得到下图,可见整篇文章内容都是在class为booklist clearfix的标签中
这里写图片描述

import requests
from pyquery import PyQuery as pq
def crawle():
    url='https://www.qtshu.com/zetianji/'
    req=requests.get(url=url)
    req.encoding='utf-8'
    html=req.text
    # print(html)
    #初始化pyquery对象
    doc=pq(html)
    #传入css选择器
    items=doc('.booklist ul li').items()
    for each in items:
        title=each.text()
        url=each.find('a').attr('href')
        print(title,url)


crawle()

这里写图片描述
只需要在url前面加上’https://www.qtshu.com/zetianji/‘就可以得到每章的链接了

那么得到链接后当然该爬取小说正文了,依然利用pyquery解析网页

def Text(url):
    req=requests.get(url=url)
    req.encoding='utf-8'
    html=req.text
    doc=pq(html)
    item=doc('.contentbox p').text()
    print(item)


# crawle()
url='https://www.qtshu.com/zetianji/2988454.html'
Text(url)

这里写图片描述

接下来综合代码:

import requests
from pyquery import PyQuery as pq
def crawle():
    url='https://www.qtshu.com/zetianji/'
    req=requests.get(url=url)
    req.encoding='utf-8'
    h
如何利用Python爬虫爬取小说网站并保存到txt文件 本人特别爱看网络小说,但是呢,有些小说网站的弹窗广告啊、悬浮广告太烦人,正好最近在研究Python,就来试试利用Python把小说站的小说爬下来,并保存到txt文件里。这样就可以直接使用手机打开txt来看了。并且呢,我也能熟悉利用python抓取文本数据的方法。 以爬取靠谱小说网的《伏天氏》这本小说的章节内容为例,目标url:http://www.kpxsw.com/0_479.html 第一步:选取文章列表其中某一章,检查网页,可以找到这本小说所有章节的链接和名称。 写出xpath表达式提取出hr 阅读详情

相关推荐

Python爬虫 - 简单的完整小说爬取

Python 爬虫爬取完整小说 文章目录Python 爬虫爬取完整小说前言一、基础与环境1.1 Web元素审查元素1.2 Requests、lxml库的安装(1)Requests库和lxml库安装(2)Requests库简单介绍(3)lxml库简单介绍二、使用步骤分为目录爬取,小说章节爬取,完整小说爬取2.1 目录爬取2.1.1 使用Requests获取页面信息2.1.2 使用lxml中的规则进行信息提取2.1.3 使用流的形式写入到文件中2.2 小说章节爬取2.2.1 读取 title 文件 获得 url

x_hhhhhh的博客 1万+

python爬虫实战篇(知识讲解+爬取小说)

大家谨记爬虫只是用来方便大家从互联网上检索信息,获取免费资源,不得以危害或者窃取对方资源使用为目的进行违法犯罪。牢记网络安全法。 1.爬虫的准备工作 安装第三方库-requests lxml 使用pip命令直接安装requests pip install requests pip install lxml 如果出现失败,请检查网络,或者换源使用阿里云下载(直接换源比较推荐)。 2.爬虫介绍以及基本使用到的方法介绍 概念:(爬虫又被称为网页蜘蛛,网络机器人)就是模拟浏览器发送网络请求,接收请求响应,一种按照

2401_85901755的博客 4289

python爬虫小说爬取

python爬虫小说爬取前言拿到一个网站最重要的就是分析分析提取每一个链接的内容2.读入数据内容处理有了一个链接里面的小说内容就可以扩展到所有标签的内容了完整代码结果及总结 前言 练习一下爬虫过程,就在网上随便找了一个小说网站 那就第一个吧,让我开始快乐的爬取 拿到一个网站最重要的就是分析分析 F12 大法最为好用 拿这一周最火的小说为例 点开之后就是小说内容了,还有下一篇上一篇的链接,我们先找到所有内容的链接目录,方便列出所有链接 那我们拿到了所有的 li 标签就是存链接内容的 放在一个块元素里

qq_46540840的博客 6295

Python爬虫之爬取小说

(^_−)☆本喵的放松方式是看小说,而且类型不限,属于偏好成谜的那一种。所以从爬取完天气预报开始,我就开始想着爬取小说,编写了一个还不算完善的爬取小说程序,期待你们的完善。 小说来源: 努努书坊:https://www.kanunu8.com/ 山海经:https://www.kanunu8.com/book3/7766/index.html 解析页面源代码: 在页面源...

青柚的博客 1万+

Python网络爬虫入门教程:从抓取数据到应用实现

本文将通过一个简单的例子,带你了解Python网络爬虫的基本原理与应用。不过,在使用爬虫时,务必注意遵守网站的法律法规,合理设置抓取频率,避免对网站造成负担。:网络爬虫通过模拟浏览器向网站发送请求,获取网页内容,然后提取其中需要的数据。Python网络爬虫是一项强大而灵活的技术,通过它可以帮助我们自动化地从互联网上提取有价值的数据。:网页内容通常是HTML格式,通过分析网页的HTML结构,可以定位到需要的数据。为了让你对爬虫的应用有更深入的理解,我们来做一个小项目——抓取小说网站中的章节标题和内容。

2403_90036899的博客 3156

python爬虫实战-小说爬取

书籍的好处就在于权威和体系健全,刚开始学习的时候你可以只看视频或者听某个人讲课,但等你学完之后,你觉得你掌握了,这时候建议还是得去看一下书籍,看权威技术书籍也是每个程序员必经之路。Python所有方向路线就是把Python常用的技术点做整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。光学理论是没用的,要学会跟着一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。获取书名、作者、状态、热度、简介等数据。

Avaricious_Bear的博客 2372

python爬虫简单实例-爬取17K小说网小说

什么是网络爬虫? 网络爬虫(Web Spider),又被称为网页蜘蛛,是一种按照一定的规则,自动地抓取网站信息的程序或者脚本。 爬虫流程 先由urllib的request打开Url得到网页html文档 浏览器打开网页源代码分析元素节点 通过Beautiful Soup或者正则表达式提取想要的数据 存储数据到本地磁盘或数据库(抓取,分析,存储) 简单实例 爬取17K小说网(https://www...

端木胥的博客 2898

实战指南:如何用Kamailio+FreeSWITCH搭建高并发企业通信系统(附配置模板)

本文提供了一份实战指南,详细介绍了如何利用Kamailio与FreeSWITCH构建高并发企业通信系统。通过将Kamailio作为高性能SIP信令平面处理路由与负载均衡,FreeSWITCH作为媒体与应用平面负责通话与业务逻辑,实现信令与媒体分离的电信级架构。文章深入解析了架构设计、核心配置、集群部署与性能优化,并附有配置模板,旨在帮助企业构建可水平扩展、高可用的通信解决方案。

dell8的博客 374

LaTeX公式转Word竟这么简单?Python三行代码实现学术论文格式无忧

本文介绍如何利用Python的latex2word库,仅需三行代码即可将LaTeX数学公式精准转换为Word原生Office Math对象,解决学术写作中LaTeX与Word格式割裂的难题。该方法支持批量处理、格式保真,并能与Markdown、Jupyter Notebook等工具集成,构建自动化写作流程,实现学术论文格式无忧。

qsc90123456的博客 302

【云迁移工具RDA】迁移常见问题

Agent无法正常启动,Linux系统提示“SMS.0201 Failed to start sms agent!”,Windows系统提示“SMS.0201 源端主机网络繁忙,无法连接api网关”。该问题通常是由于源端没有通公网,或者没有按照要求配置hosts,无法与iam或者sms通信导致。需要排查源端网络。1.登录源端服务器。2.检查源端是否能正常访问互联网,若无法访问,请处理后重新启动Agent。可参考弹性公网IP Ping不通检查源端的DNS,防火墙,安全组、本地网络等。

2404_89358774的博客 1489

NVIDIA DRIVE SDK学习(二)——NvMedia

可以通过使用NvSciBuf API通过NvMedia Tensor属性分配NvSciBuf来创建NvMedia张量。由于NvSciBuf API有助于NvMedia和NVIDIA®CUDA®之间的数据共享,这使得分配的张量可以在NvSciBuf API允许的情况下重复使用。它支持图像聚合操作。NvSciSync组件使得NvMedia组件可以与其他组件保持同步,比如CUDA组件、基于NvSciSync的组件等。立体视差模式:在这种模式下,该模块通过左图像和右图像来产生立体视差,从而进行物体深度测量。

weixin_39592381的博客 3052

Fluent动网格+滑移网格+重叠网格对比介绍(以震荡水翼flapping foil为例)

初学fluent笔记,本文主要包含: Flapping foil在fluent内的几种实现方式 在哪设置动网格、滑移、重叠网格 flapping的UDF 示例 写在前面:Fluent在预览网格运动/提交计算之前,注意保存一个cas版本。 -------------------------Flapping foil 网格几种组合实现方式:---------------------- 直接重叠网格,overset, 需要建立两个几何part,part要重合。水翼局部区域(component),背景网格(ba

深海民工CFDer 2万+

IsaacLab从入门到精通(二) 导入自定义机器人

IsaacLab系列第二讲,导入自定义的机器人及设置

DejaWu33的博客 8476

视频监控设备(NVR、IPC等)如何通过国标GB28181接入到视频监控平台,以及接入过程如何测试视频接入是否成功

GB/T28181标准广泛的应用,视频监控设备通过国标GB28181接入视频监控平台的过程变成程序化、标准化的互联过程,确保了视频监控设备能够在不同系统、不同网络环境下实现远程、跨区域、跨级别的访问和控制。版本有GB28181-2011、2016、2022几个常用版本,威迪斯特的视频监控平台完全支持GB28181的这几个版本,能够实现不同品牌视频监控设备的国标视频接入(国标视频监控接入),或者为国标28181视频接入(国标28181视频监控接入),也为国标281818接入(国标GB/T28181接入。

weixin_70208651的博客 1万+

PGM-Explainer实验总结

PGM-Explainer建立了一个概率图模型,为GNN提供实例级解释。 论文标题:PGM-Explainer: Probabilistic Graphical Model Explanations for Graph Neural Networks 论文地址:2010.05788.pdf (arxiv.org) PGM-Explainer实验 实验目的 研究PGM-Explainer的有效性 实验方案 合成数据集的节点分类 与其他解释器做对比实验 使用六个合成数据集。 每个输入图都是一个

笔记|思路|总结 1万+

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

下一篇: python3爬虫实战(二):用Appium抓取手机app微信的数据
Fan_shui
博客等级 码龄8年 77粉丝 9原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值