Python学习笔记(15) 网络爬虫使用proxy实现自动换IP防封锁

使用proxy_pool来为爬虫程序自动更换代理IP 阅读详情

如果网络爬虫访问某个网站太频繁,很可能被目标网站封锁,虽然网站封锁有很多种,需要不同的应对方案,但是,最常用的缓解封锁的方案是换IP,关于其他封锁应对方案大家可以跟帖讨论。

换IP也有两个方案:

  1. 利用VPN客户端软件自动换IP:这个方案是在操作系统级的,所以不用对网络爬虫软件做设置,IP换了,爬虫软件自然会用新IP
  2. 利用proxy服务定时获得新的proxy服务网址:这个方案是在爬虫控制下的,所以,可以选择合适的时机连接某个proxy,通过proxy访问目标网站,目标网站就把访问的源头当成了这个proxy,通过定时换proxy,目标网站会认为是不同的源头来的,降低被封锁的风险。由于这个方案是在爬虫控制下的,所以能避免时机不对的问题,比如,正在下载文件的时候换IP就会打断下载过程,而在爬虫控制下,会选择合适的时机。

本文讲解方案2,由于各个proxy服务的api各不相同,每接入一种proxy服务,都要修改网络爬虫软件,本文只讲解接入芝麻http的方法,如果您需要接入其他proxy服务,需要与集搜客技术支持联系。

1.  获得提取IP的网址

在芝麻http网站上,顶部菜单有“获取API”,进入到获取API页面,假定购买了按次提取的服务,如下图进行设置,以获得提取IP的网址。

注意提取数量:选择1个,因为爬虫每次只用一个。其他选择看上图,通过这个API接口,会返回提取到的IP和端口号,集搜客网络爬虫需要解析这个返回结果,只支持JSON格式的返回结果,所以,要像上图那样设置。

点击“生成API链接”,就能得到一个网址,这个网址是要配置到集搜客网络爬虫中的,爬虫会每隔

Python网络爬虫技术 本文介绍了Python网络爬虫的技术实现方案,包含请求处理、数据解析和存储等核心模块。文章详细讲解了静态/动态网页爬取方法,涉及requests、BeautifulSoup、Selenium等工具库的使用,并涵盖了代理轮换、异常处理、反反爬策略等关键技术。同时提供了异步爬取、性能优化等进阶内容,以及新闻、电商等实战案例。最后强调了爬虫的合法性问题,建议遵守robots协议,并推荐了相关学习资源。全文采用模块化代码结构,完整实现了从网页请求到数据存储的爬虫工作流程。 阅读详情

相关推荐

Python爬虫老被‘踢下线’?手把手教你用proxy_pool搭建免费IP代理池(附完整代码)

本文详细介绍了如何利用proxy_pool搭建免费IP代理池,解决Python爬虫频繁断连的问题。通过实战指南,包括环境准备、配置调优、服务启动与监控,帮助开发者构建高可用代理池,有效应对IP封锁机制,提升爬虫稳定性。

weixin_30952535的博客 1047

Python网络爬虫权威指南2026实战:从零到精通的完整学习路线与工程化实践

网络爬虫作为自动化获取网页数据的关键技术,其核心在于模拟浏览器行为与高效解析HTML结构。理解HTTP协议、请求响应机制及会话管理是构建稳定爬虫的基础,这直接关系到数据抓取的效率与合规性。在工程实践中,爬虫的价值不仅在于数据采集,更在于为数据分析、机器学习提供高质量的数据源,广泛应用于舆情监控、价格追踪、搜索引擎索引等场景。面对日益复杂的反爬策略,如请求头验证、IP频率限制及JavaScript动态渲染,掌握Scrapy框架与反爬对抗技术成为现代爬虫工程师的必备技能。本文基于《Python网络爬虫权威指南》

weixin_30905133的博客 346

高效Python爬虫实战:如何避免IP封锁与验证码困扰

本文探讨了应对大规模网页抓取时IP封锁和验证码检测的解决方案。通过使用代理池轮换IP、模拟真实用户行为(如轮换User-Agent和Session管理)以及借助验证码破解服务(如2Captcha),可以有效规避反爬机制。此外,合理的请求间隔、限速策略和容错机制能进一步提升爬虫稳定性。综合运用这些技术手段,可显著提高爬虫的抓取效率和成功率。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 993

Python 爬虫实战:批量抓取免费代理IP地址,提升网络爬虫效率与匿名性

在网络爬虫的实战过程中,代理 IP 的使用至关重要。代理不仅能够帮助我们绕过反爬机制,还能保证爬虫在长时间运行时不被封禁。然而,购买代理 IP 的成本往往较高,特别是在处理大量数据时,更需要大量的。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1288

Python 爬虫实战:IP 代理池的搭建与动态使用

本文系统阐述了IP代理池在爬虫开发中的核心价值与实现方案。首先分析了三种代理类型(透明/匿名/高匿)的爬虫适配性,详细介绍了代理池"采集-验证-存储-调度"的闭环架构。通过Redis实现方案,结合豆瓣电影Top250的实战案例,展示了代理IP的动态采集、多线程验证、分级存储和智能调度(最快响应/轮询/加权随机)全流程。文章还深入探讨了性能优化策略(多线程验证、分级存储)和反反爬技巧(代理混淆、频率控制)。最终构建出可自动更新、动态切换的高可用代理池,有效突破目标网站的IP限制,为大规模爬

2503_91057718的博客 1766

Halcon实战:5分钟搞定工业零件中的圆孔检测(附完整代码)

本文详细解析了如何利用Halcon的hough_circle算法在5分钟内高效完成工业零件中的圆孔检测。通过优化图像采集、智能预处理和参数化边缘检测,解决了金属反光、油污干扰等工业场景常见问题,并提供了完整的代码示例和实战案例,显著提升检测精度和效率。

weixin_29061997的博客 239

保姆级教程:在Ubuntu 22.04上用Conda搞定nuPlan数据集环境(Python 3.9 + PyTorch)

本文提供了一份详细的Ubuntu 22.04环境下使用Conda配置nuPlan自动驾驶数据集的保姆级教程,涵盖Python 3.9安装、Conda环境管理、PyTorch配置及数据集可视化验证等关键步骤,帮助开发者高效搭建开发环境。

weixin_29061997的博客 255

麒麟V10系统命令实战指南:从入门到精通

本文为麒麟V10操作系统用户提供了一份从入门到精通的命令行实战指南。内容涵盖文件管理、进程监控、网络诊断、文本处理及系统管理等核心场景,旨在帮助用户转变思维,掌握高效解决实际问题的系统命令技巧,从而提升在麒麟V10环境下的运维与工作效率。

sat99的博客 594

基于Simulink实现电动汽车制动能量回收系统的仿真

通过上述步骤,我们成功实现了基于Simulink的电动汽车制动能量回收系统的仿真研究。该系统能够全面评估制动能量回收系统的性能,验证控制策略的有效性,并通过优化设计提高能量回收效率和制动安全性。引入智能预测:结合人工智能技术,实现更智能的能量回收控制策略。扩展功能:增加对多种车型和制动场景的支持,提升系统通用性。实验验证:将仿真模型应用于实际硬件,进行实验验证,评估其在实际工况下的表现。

xiaoheshang_123的博客 336

仅使用 Python 创建的 Web 应用程序(前端版本)第03章Streamlit-多页面

接下来,我们将解释多页面切换。Streamlit 没有“多页面”或“页面路由”等功能。另一方面,通过根据用户动作切换要执行的功能,可以使其看起来好像存在“多个页面”。注意:我认为它类似于 SinglePageApplication (SPA)。然而,根据 React、Vue 等中使用的 URL 路径来更改页面的路由很困难。还有一个用于获取查询参数的实验性 API,但如果您确实需要这种功能,我认为认真尝试编写 React 或 Vue 是个好主意。我们来看一个通过按下按钮来切换页面的示例,如下所示。

xianyinsuifeng的博客 1329

Python 实现生命游戏及进化模拟完整指南

生命模拟是进化计算的一个特定子集,模拟了自然界中所观察到的自然过程,例如粒子或鸟群的聚集方式。生命模拟只是用来探索和优化问题的模拟形式之一,还有很多其他形式的模拟,可以更好地建模各种过程,但它们都源于康威生命游戏 (Conway’s Game of Life)。在本节中,我们将介绍生命模拟的基本概念,并使用 Python 实现康威生命游戏。

盼小辉丶的博客 7万+

ITIL 4 讲解:服务目录

最近一直比较忙,没有时间写文章了。今天有空,写写服务目录。 在最近的项目中,服务目录是比较热的话题。金融行业大部分银行、证券、金融公司都实行ITIL流程管理有些年头了,ITIL中最基础的服务请求、事件、问题和变更都已经实施完毕,目前客户在运维领域做的项目大部分都要求整理服务目录,实行服务级别管理。 服务目录介绍 首先解释一下什么是服务目录。服务目录在ITIL 4的定义是:有关服务提供商的所有服务和服务产品的结构化信息,与特定目标受众相关。这个解释有些晦涩难懂,简单来说就是提供给业务用户的服务项,就像饭

雅子MM的专栏 6467

小孙学变频学习笔记(二)变频器的逆变电路

本文主要介绍了变频器中逆变电路的核心器件IGBT及其应用。IGBT是一种电压控制型三端半导体开关器件,具有开关频率高、功耗低的优点,在变频器中仅使用截止和饱和导通状态。文章详细分析了IGBT的结构特性、与晶闸管的区别,以及由四个IGBT组成的直流转交流逆变电路原理。重点阐述了IGBT并联反向二极管的作用:提供电流反向通路、避免反向电压损坏器件、提高开关效率等。最后提供了相关学习参考网址供读者进一步研究。

qq_43091070的博客 1196

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

深度学习工具包 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")

上一篇: Python学习笔记(14) 多层嵌套样例复制
下一篇: Python学习笔记(16) python爬虫实现自动网页截屏
Python老王
博客等级 码龄7年 159粉丝 224原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值