一个简单的python案例,用正则采集小说网站

初识Python爬虫,使用正则表达式提取数据 正则:用来匹配字符产的一门表达式语言1.正则支持普通字符2.元字符,即一个符号匹配部分对应内容\d 匹配0-9的数字 \d\d 一行提取2个数字\w 匹配数字、字母、下划线(0-9、a-z、_)\W \w取反\D \d取反[abc] 自定义匹配abc[^abc 】(英文的】)[abc]取反. 除了换行符都可以匹配。量词控制,前面元字符出现的频次+,前面的元字符出现1次或多次*,前面的元字符出现0次或多次。贪婪匹配,尽可能多的匹配数据?前面的元字符,出现0次或一次。 阅读详情

目录标题

前言

嗨喽~大家好呀,这里是魔王呐 ❤ ~!

使用Python抓取xx阁小说需要用到 requests 库和正则表达式模块 re,下面是一个具体的实现步骤:

1. 首先需要使用 requests 库请求小说的页面

例如:

import requests

url = 'https://*****.com.cn/book/123456/'
response = requests.get(url)
response.encoding = 'utf-8'

在请求后需注意设置编码,否则可能会出现乱码。

python资料、源码、教程\福利皆: 点击此处跳转文末名片获取

2. 获取小说的标题

可以使用正则表达式模块中的 re.findall() 方法,

例如:

import re

title_pattern = re.
Python爬虫入门学习实践——爬取小说 Python爬虫入门学习实践——爬取小说 前言 本学期开始接触python,python是一种面向对象的、解释型的、通用的、开源的脚本编程语言,我觉得python最大的优点就是简单易用,学习起来比较上手,对代码格式的要求没有那么严格,这种风格使得我在编写代码时比较舒适。爬虫作为python的最为吸引我兴趣的一个方面,在学习之后可以帮助我们方便地获取更多的数据源,从而进行更深层次更有效的数据分析,获得更多的价值。 爬取小说思路 首先我们肯定是对小说网站进行观察,辨别小说网站是静态还是动态的,此次爬取的目标是笔 阅读详情

相关推荐

Python爬虫数据抽取:使用正则表达式提取网页内容

通过使用正则表达式,我们可以方便地从HTML源代码中提取出我们需要的数据。然而,在处理复杂的HTML结构时,使用专门的HTML解析库会更加方便和可靠。现在我们已经获取到了网页的HTML源代码,接下来我们可以使用正则表达式来提取我们需要的数据。接下来,我们需要获取网页的HTML源代码。除了提取链接,我们还可以使用正则表达式来提取其他类型的数据,比如提取电子邮件地址、日期、价格等等。以上示例只是展示了正则表达式的一小部分功能,正则表达式的语法非常强大,可以根据不同的需求进行灵活的匹配和提取。

CyberNova的博客 568

飞书文档API深度使用指南:如何用n8n社区节点绕过HTTP Request的复杂配置

本文详细解析了如何利用n8n社区节点简化飞书文档API的集成过程,绕过复杂的HTTP Request配置。通过n8n-feishu-lite社区节点,开发者可以轻松实现飞书文档的创建、编辑和查询操作,大幅提升自动化工作流的效率。文章还提供了高级应用场景和性能优化建议,帮助开发者更好地利用飞书开放平台的API功能。

weixin_29227585的博客 83

零基础学习大气污染模式(WRF、WRF-chem、smoke、camx等)

零基础学习大气污染模式(WRF、WRF-chem、smoke、camx等)

weixin_56135535的博客 654

containerd镜像加速配置全解析:从host.toml到config.toml的演进与实践

本文全面解析了containerd镜像加速的配置方法,重点对比了传统的config.toml集中式配置与现代的host.toml模块化配置的演进与优劣。文章通过实战演示,详细指导如何为docker.io、registry.k8s.io等常见仓库配置host.toml加速,并提供了生产环境下的最佳实践、故障排查与性能优化建议,帮助用户显著提升镜像拉取效率与系统稳定性。

jenkins8butler的博客 698

电力电子技术文章:ACOT控制模式在Buck变换器中的频率稳定性分析

本文深入分析了ACOT控制模式在Buck变换器中实现频率稳定性的原理与优势。通过对比传统COT模式,阐述了ACOT如何通过自适应调整导通时间,将开关频率锁定在设定值,从而有效应对输入电压与负载变化。文章还探讨了其在轻载DCM模式下的高效与平滑切换特性,并提供了关键的设计考量与实战指南。

cc789的博客 1151

SEMI E40标准的加工任务状态模型(Process Job State Model)解析

半导体制造设备的自动化控制离不开对加工任务(Process Job)的精细管理。SEMI E40标准定义了加工任务的全生命周期状态模型。分层建模,支持嵌套与并发子状态,确保复杂流程的灵活控制。SEMI E40通过。

bengg123的博客 1774

Linux系列:SecurtCRT中的密码如何找回

【代码】Linux系列:SecurtCRT中的密码如何找回。

NIO4444 1086

SAP Fiori 会话超时全解析:从 Launchpad 到 Identity Authentication 的统一策略

SAP Fiori会话超时机制解析与配置策略 本文深入探讨SAP Fiori项目中的会话超时机制,分析其对系统安全和用户体验的双重影响。文章系统拆解了SAP Fiori Launchpad与SAP Cloud Identity Services之间的会话超时工作原理,重点介绍了两种超时机制:服务器驱动的超时(通过SESSION_TIMEOUT_STOP_DATA_REFRESH参数控制)和UI驱动的超时(通过SESSION_TIMEOUT_INTERVAL_IN_MINUTES参数控制)。文中结合制造业产线

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 213

对偶分解算法详解及其Python实现

对偶分解算法是一种广泛应用于求解凸优化问题的有效方法,尤其在大规模数据处理和分布式计算中展现出强大的实用性。在许多实际应用中,直接求解原始问题可能由于计算复杂度过高、资源受限或问题规模过大而变得不可行。这时,对偶分解方法为我们提供了一种高效的替代方案。对偶分解算法的核心思想是将复杂的原问题转化为其对应的拉格朗日对偶问题。通过引入拉格朗日乘子并构造对偶函数,该方法在一定程度上简化了问题的求解过程。特别是,对于包含多个约束条件的大规模优化问题,对偶分解可以将原问题分解为若干个小规模、相互独立的子问题。

闲人编程的博客 1752

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

深度学习工具包 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'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('DeepLearnToolbox'));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('state',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'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',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 = 'sigm';%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, 'Too big error');```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('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';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)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';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, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% 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'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 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, 'Too big error');```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('state',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, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',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, 'Too big error');%% ex3 neural net with dropoutrand('state',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, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % 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, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % 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, 'Too big error');%% 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('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % 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, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

上一篇: Python采集双色球历史开奖信息,看看哪个号中奖概率更大
下一篇: 酷炫音乐盒: python打造自己的音乐播放器
魔王不会哭
博客等级 码龄5年 6003粉丝 394原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值