Python3 大型网络爬虫实战 001 --- 搭建开发环境

超详细!Python爬虫实战案例 阅读详情
AI摘要

本文介绍了如何在Windows 10上搭建Python3爬虫开发环境,包括安装Python3、PyCharm IDE、Visual Studio 2015、升级pip并安装Scrapy、lxml、Twisted、pywin32等第三方库,以及使用PowerCmd作为命令行工具。通过这些步骤,为后续的Scrapy爬虫项目开发做好准备。


我使用的电脑: Windows 10 64位

前言

开发Python爬虫有很多种方式,从程序的复杂程度的角度来说,可以分为:爬虫项目和爬虫文件。
相信有些朋友玩过Python的urllib模块,一般我们可以用该模块写一些爬虫文件,实现起来非常方便,但做大型项目的时候,会发现效率不是太好、并且程序的稳定性也不是太好。
Scrapy是一个Python的爬虫框架,使用Scrapy可以提高开发效率,并且非常适合做一些中大型爬虫项目。
简单来说,urllib库更适合写爬虫文件,scrapy更适合做爬虫项目。

本套专栏,就来讲解如何做爬虫项目。本篇博客是第一篇博客:搭建开发环境。

1 . 安装Python3

到官网下载就可以了,下载一个Python3.5版本就可以,傻瓜式安装。

Python 3 被默认安装在:C:\Users\[Username]\AppData\Local\Programs\Python\Python35 这个路径里面。

2 . 安装Python程序开发集成开发环境 — PyCharm IDE 2016.1.4

软件下载:https://www.jetbrains.com/pycharm/download/#section=windows

注意:

Professional是完整版的,但是需要注册码

注册方法:http://blog.youkuaiyun.com/tianzhaixing2013/article/details/44997881

我这次安装的是PyCharm 2016。

Community是免费版的,但是软件里面的Terminal是不能使用的。

3 . 安装 Visual Studio 2015 软件

要知道:为什么需要 Visual Studio 软件了。(参考这个网站)

如果不安装,当中你执行pip install third-package-name时,有时会出现下面这个错误:error: Unable to find vcvarsall.bat

Alt text

安装Visual Studio 2015 软件是为了安装里面的Python Tools 2.2.5 for Visual Studio 2015软件。

下载和安装 Visual Studio 2015 软件 的方法在这里。

4 . 升级 pip 工具

在DOS窗口中执行下面的命令来升级pip工具。

python -m pip install --upgrade pip

5 . 安装一些第三方库

lxml、Twisted、pywin32、scrapy

lxml是一种可以迅速、灵活地处理 XML。
Twisted是用Python实现的基于事件驱动的网络引擎框架。
pywin32提供win32api。
Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架。


我们安装的是python3.5,并且我的电脑是64位的,所以:下载:

lxml‑3.6.4‑cp35‑cp35m‑win_amd64.whl

Twisted‑16.5.0‑cp35‑cp35m‑win_amd64.whl

pywin32‑220.1‑cp35‑cp35m‑win_amd64.whl

scrapy(直接使用命令:pip.exe install scrapy 来安装。)


Python安装第三方库的方法:http://blog.youkuaiyun.com/github_35160620/article/details/52203682

注意:如果你的电脑之前安装了Python2,那么Python2 有自己的pip工具,Python3 也是有自己的pip工具,所以,如果你在DOS命令行上执行pip install some-package-name命令的时候,系统会使用哪个pip工具呢?是python2的pip,还是python3的pip?

这个问题,你可以在这篇博客里得到解决答案:http://www.aobosir.com/blog/2016/11/23/pip-install-python2-python3/


下载后,在我的电脑上是这样安装:

安装 lxml:

C:\Users\AOBO>cd C:\Users\AOBO\AppData\Local\Programs\Python\Python35\Scripts
C:\Users\AOBO\AppData\Local\Programs\Python\Python35\Scripts>pip.exe install D:\software_install_package_win\python\some-Python-third-packages\lxml-3.6.4-cp35-cp35m-win_amd64.whl
Processing d:\software_install_package_win\python\some-python-third-packages\lxml-3.6.4-cp35-cp35m-win_amd64.whl
Installing collected packages: lxml
Successfully installed lxml-3.6.4

安装 Twisted :(执行到Collecting constantly>=15.1 (from Twisted==16.5.0)这句时,卡住了,我按了 Ctrl+C 才继续执行下去。自动下载了下面的:constantly、incremental、zope.interface 这三个依赖库)

C:\Users\AOBO\AppData\Local\Programs\Python\Python35\Scripts>pip.exe install D:\software_install_package_win\python\some-Python-third-packages\Twisted-16.5.0-cp35-cp35m-win_amd64.whl
Processing d:\software_install_package_win\python\some-python-third-packages\twisted-16.5.0-cp35-cp35m-win_amd64.whl
Collecting constantly>=15.1 (from Twisted==16.5.0)
#(执行到这卡住了,我按了 Ctrl+C 才继续执行下去。自动下载了下面的:constantly、incremental、zope.interface 这三个依赖库)
  Downloading constantly-15.1.0-py2.py3-none-any.whl
Collecting incremental>=16.10.1 (from Twisted==16.5.0)
  Downloading incremental-16.10.1-py2.py3-none-any.whl
Collecting zope.interface>=4.0.2 (from Twisted==16.5.0)
  Downloading zope.interface-4.3.2-cp35-cp35m-win_amd64.whl (136kB)
    100% |████████████████████████████████| 143kB 7.1kB/s
Requirement already satisfied: setuptools in c:\users\aobo\appdata\local\programs\python\python35\lib\site-packages (from zope.interface>=4.0.2->Twisted==16.5.0)
Installing collected packages: constantly, incremental, zope.interface, Twisted
Successfully installed Twisted-16.5.0 constantly-15.1.0 incremental-16.10.1 zope.interface-4.3.2

安装pywin32:

C:\Users\AOBO\AppData\Local\Programs\Python\Python35\Scripts>pip.exe install D:\software_install_package_win\python\some-Python-third-packages\pywin32-220.1-cp35-cp35m-win_amd64.whl
Processing d:\software_install_package_win\python\some-python-third-packages\pywin32-220.1-cp35-cp35m-win_amd64.whl
Installing collected packages: pywin32
Successfully installed pywin32-220.1

安装scropy:

C:\Users\AOBO\AppData\Local\Programs\Python\Python35\Scripts>pip.exe install scrapy
Collecting scrapy
  Downloading Scrapy-1.2.1-py2.py3-none-any.whl (294kB)
    100% |████████████████████████████████| 296kB 338kB/s
Collecting service-identity (from scrapy)
  Downloading service_identity-16.0.0-py2.py3-none-any.whl
Collecting six>=1.5.2 (from scrapy)
  Downloading six-1.10.0-py2.py3-none-any.whl
Collecting w3lib>=1.15.0 (from scrapy)
  Downloading w3lib-1.16.0-py2.py3-none-any.whl
Collecting PyDispatcher>=2.0.5 (from scrapy)
  Downloading PyDispatcher-2.0.5.tar.gz
Requirement already satisfied: Twisted>=10.0.0 in c:\users\aobo\appdata\local\programs\python\python35\lib\site-packages (from scrapy)
Requirement already satisfied: lxml in c:\users\aobo\appdata\local\programs\python\python35\lib\site-packages (from scrapy)
Collecting cssselect>=0.9 (from scrapy)
  Downloading cssselect-1.0.0-py2.py3-none-any.whl
Collecting parsel>=0.9.3 (from scrapy)
  Downloading parsel-1.1.0-py2.py3-none-any.whl
Collecting queuelib (from scrapy)
  Downloading queuelib-1.4.2-py2.py3-none-any.whl
Collecting pyOpenSSL (from scrapy)
  Downloading pyOpenSSL-16.2.0-py2.py3-none-any.whl (43kB)
    100% |████████████████████████████████| 51kB 4.7MB/s
Collecting pyasn1 (from service-identity->scrapy)
  Downloading pyasn1-0.1.9-py2.py3-none-any.whl
Collecting pyasn1-modules (from service-identity->scrapy)
  Downloading pyasn1_modules-0.0.8-py2.py3-none-any.whl
Collecting attrs (from service-identity->scrapy)
  Downloading attrs-16.2.0-py2.py3-none-any.whl
Requirement already satisfied: constantly>=15.1 in c:\users\aobo\appdata\local\programs\python\python35\lib\site-packages (from Twisted>=10.0.0->scrapy)
Requirement already satisfied: zope.interface>=4.0.2 in c:\users\aobo\appdata\local\programs\python\python35\lib\site-packages (from Twisted>=10.0.0->scrapy)
Requirement already satisfied: incremental>=16.10.1 in c:\users\aobo\appdata\local\programs\python\python35\lib\site-packages (from Twisted>=10.0.0->scrapy)
Collecting cryptography>=1.3.4 (from pyOpenSSL->scrapy)
  Downloading cryptography-1.6-cp35-cp35m-win_amd64.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 257kB/s
Requirement already satisfied: setuptools in c:\users\aobo\appdata\local\programs\python\python35\lib\site-packages (from zope.interface>=4.0.2->Twisted>=10.0.0->scrapy)
Collecting cffi>=1.4.1 (from cryptography>=1.3.4->pyOpenSSL->scrapy)
  Downloading cffi-1.9.1-cp35-cp35m-win_amd64.whl (158kB)
    100% |████████████████████████████████| 163kB 322kB/s
Collecting idna>=2.0 (from cryptography>=1.3.4->pyOpenSSL->scrapy)
  Downloading idna-2.1-py2.py3-none-any.whl (54kB)
    100% |████████████████████████████████| 61kB 4.4MB/s
Collecting pycparser (from cffi>=1.4.1->cryptography>=1.3.4->pyOpenSSL->scrapy)
  Downloading pycparser-2.17.tar.gz (231kB)
    100% |████████████████████████████████| 235kB 311kB/s
Installing collected packages: six, pycparser, cffi, pyasn1, idna, cryptography, pyOpenSSL, pyasn1-modules, attrs, service-identity, w3lib, PyDispatcher, cssselect, parsel, queuelib, scrapy
  Running setup.py install for pycparser ... done
  Running setup.py install for PyDispatcher ... done
Successfully installed PyDispatcher-2.0.5 attrs-16.2.0 cffi-1.9.1 cryptography-1.6 cssselect-1.0.0 idna-2.1 parsel-1.1.0 pyOpenSSL-16.2.0 pyasn1-0.1.9 pyasn1-modules-0.0.8 pycparser-2.17 queuelib-1.4.2 scrapy-1.2.1 service-identity-16.0.0 six-1.10.0 w3lib-1.16.0

查看 scrapy 是否安装成功:(执行scrapy -h 命令,如果能输出信息,说明安装成功)

C:\Users\AOBO>scrapy -h
Scrapy 1.2.1 - no active project

Usage:
  scrapy <command> [options] [args]

Available commands:
  bench         Run quick benchmark test
  commands
  fetch         Fetch a URL using the Scrapy downloader
  genspider     Generate new spider using pre-defined templates
  runspider     Run a self-contained spider (without creating a project)
  settings      Get settings values
  shell         Interactive scraping console
  startproject  Create new project
  version       Print Scrapy version
  view          Open URL in browser, as seen by Scrapy

  [ more ]      More commands available when run from project directory

Use "scrapy <command> -h" to see more info about a command

C:\Users\AOBO>

检查所有刚刚安装的库是否安装成功:

启动PyCharm 软件,新建一个工程:

Alt text

Alt text

刚刚安装的库在这里可以看到:

Alt text

安装成功。


6 . 一个超好的命令行串口软件 — PowerCmd

PowerCmd 是一款Windows CMD 的增强工具。

下载安装地址:http://www.aobosir.com/blog/2016/11/23/powercmd-install/

这个软件真的很喽,像我执行scrapy -h 这样的命令,都打印不出信息,在DOS窗口里面是有信息打印出来的。



测试环境

1 . 执行 scrapy -h,如果有打印出来信息,说明Scrapy 安装成功。

2 . 执行 scrapy bench ,如果遇到问题,说明pywin32库还有需要完成的步骤。(解决问题: import win32api ImportError: DLL load failed,到这里查看解决办法。)


接下来,我们学习 Scrapy 的命令。了解了Scrapy 命令后,我学习:scrapy 爬虫项目的创建及爬虫的创建 — 实例:爬取百度标题和优快云博客。


请访问:http://www.aobosir.com/

python3简单爬虫 (爬取各个网站上的图片) 不多说。Python能做出东西。这是对编程初学者的莫大激励了吧。2333333 下面就放码了。 第一个爬虫: import urllib.request import re import os foot='huaban001' url_re=re.compile(r'<img src="(http://img.hb.aicdn.com/.+?)"') url='http://huaban.c 阅读详情

相关推荐

DP_AUX辅助通道介绍

DisplayPort(简称DP)是一个由PC及芯片制造商联盟开发,视频电子标准协会(VESA)标准化的数字式视频接口标准。其中辅助通道(AUX)是一条独立双向半双工的传输通道,它也是一对差分信号线。其数据传输速率1Mbps,用来传输配置参数与指令。

cjie221的博客 5347

从入门到精通:网络爬虫开发实战总结

学习是一种持续不断的过程,无论在什么领域,都需要不断地努力和探索。在这段爬虫学习历程中,我不仅获得了丰富的知识和技能,也结交了很多志同道合的朋友和粉丝,他们对我的学习和进步都提供了极大的支持和鼓励,支持我继续写下去。 总的来说,这段时间的学习和写作让我认识到了自己的不足和缺陷,也让我更加坚定了继续学习和进步的决心。我相信,在未来的学习和工作中,这段经历将成为我前行的动力和支撑。在这里,我将过去写过的爬虫文章总结一下,不仅是在爬虫学习这里留下一个里程碑,也是为了能够总结一下阶段性学习成果。

weixin_50804299的博客 6560

如何设计一个低代码平台

近些年来,低代码发展火热,各种低代码平台如雨后春笋纷纷崛起,这些平台各定位不同,优劣不同,用户的选择空间很大。那么,如果用户想从零开始设计一个低代码平台,该如何做呢?

Jarod_Chou的博客 8257

Python网络爬虫基础进阶到实战教程

本文是一篇关于Python网络爬虫的教程,从基础概念认识网络爬虫开始,介绍了HTML页面的组成和常用的标签属性、样式和JavaScript效果。接着详细讲解了Python中的Requests模块的get请求和实践,以及Post请求的区别和使用示例。然后介绍了Xpath解析和BeautifulSoup库的应用,演示了如何解析HTML和XML文档并提取信息。此外,还介绍了正则表达式的基本用法和在爬虫中的实际应用案例。最后,讲解了字体反爬技术和如何应对,以及Scrapy框架的入门使用。

全栈若城,专注知识分享 5697

fpga的希尔伯特变换实现

fpga的希尔伯特变换实现零.实现背景一.希尔伯特实现的基本原理2.实现1)matlab仿真1)fpga滤波器实现实现成本:fpga实现采用VIvado的FIR的IP核, 零.实现背景 因为今明工作项目需要使用到希尔伯特变换来处理问题,所以顺便就把设计流程和代码都整理下来,以便供他人使用。选用Xilinx的7系列板子,Vivado平台。 一.希尔伯特实现的基本原理 希尔伯特变换的物理意义十分简单:...

weixin_42219690的博客 1万+

STM32使用内部RC振荡器作为系统时钟开发项目--内晶振启动模板工程

STM32使用内部RC振荡器时,OSC32_IN,OSC32_OUT接法: 1)对于100脚或144脚的产品,OSC_IN应接地,OSC_OUT应悬空。 2)对于少于100脚的产品,有2种接法:    2.1)OSC_IN和OSC_OUT分别通过10K电阻接地。此方法可提高EMC性能。    2.2)分别重映射OSC_IN和OSC_OUT至PD0和PD1,再配置PD0和PD1为推挽输出

overflyme的博客 1万+

Python 3网络爬虫开发实战.PDF分享(可直接下载阅读)

Python 3网络爬虫开发实战

qq_41625306的博客 1万+

【全解析 | PTA】浙大版《Python 程序设计》题目集-第一章

Python浙大版PTA题解

wzhh_的博客 5527

Python爬虫——简单网页抓取(实战案例)小白篇

在着手写爬虫抓取网页之前,要先把其需要的知识线路理清楚。 首先:了解相关的Http协议知识; 其次:熟悉Urllib、Requests库; 再者:开发工具的掌握 PyCharm、Fiddler; 最后:网页爬取案例;

m0_74942241的博客 2万+

告别概念晕眩:用TC3xx SMU和TLF35584的配置实例,搞懂ASIL D功能安全落地

本文通过英飞凌TC3xx系列MCU的SMU模块与TLF35584电源管理芯片的协同配置实例,详细解析了如何实现符合ASIL D功能安全标准的刹车辅助ECU。文章涵盖SMU报警源配置、响应动作类型、TLF35584的安全状态管理,以及构建完整安全闭环的实践方法,帮助工程师将抽象的安全概念落地为具体设计方案。

weixin_30647065的博客 436

基于非接触式微波雷达设计的睡眠监控系统_323

本项目设计了一种基于非接触式微波雷达的睡眠监控系统,通过高精度的生理信号采集与分析,帮助用户全面了解自身的睡眠状态和健康状况。系统采用60GHz频段的R60ABD1毫米波雷达模块,实现对人体呼吸频率、心率、活动状态、体动幅度等参数的非接触式测量;结合MLX90614红外体温传感器,能够实时监测人体体温。此外,系统通过蜂鸣器报警和数据上云功能,及时向用户反馈异常生理指标,确保健康风险早期预警。数据通过ESP8266-WIFI模块上传至华为云物联网平台,用户可通过Android手机APP和Windows上位机远

499

【愚公系列】《Python网络爬虫从入门到精通》001-初识网络爬虫

随着互联网的快速发展,数据的获取与处理变得愈发重要。在这个信息爆炸的时代,如何有效地收集和利用网络上的海量数据,成为了各行业面临的一大挑战。网络爬虫,作为一种自动化获取网页信息的技术,正逐渐成为数据分析、市场研究、竞争对手监控等领域不可或缺的工具。本文将带领读者初步了解网络爬虫的基本概念、工作原理以及常见应用场景。我们将探讨爬虫的构建过程,包括如何发送请求、解析网页、存储数据等关键步骤。同时,还会涉及一些爬虫开发中的注意事项,如如何遵循网站的robots.txt协议、避免被封禁等。

愚公智库 12万+

【ubuntu24.04】auto remove后,重启,kernel panic ,please reboot your computer vfs unable to mount root fs

Ubuntu 24.04系统在运行auto remove后出现内核恐慌(kernel panic)无法启动,显示"VFS: unable to mount root fs"错误。该问题是由于当前内核被清除导致系统无法挂载根分区。解决步骤包括:1)尝试用GRUB菜单中的旧内核启动;2)在GRUB中临时编辑启动参数;3)使用Ubuntu启动盘进行chroot修复;4)使用Boot-Repair工具一键修复。成功启动后,需要重新安装linux-generic等元包,重建initramfs并更新

突围 1209

Python 网络爬虫 001 (科普) 网络爬虫简介

Python 网络爬虫 001 (科普) 网络爬虫简介1. 网络爬虫是干什么的我举几个生活中的例子:例子一: 我平时会将 学到的知识 和 积累的经验 写成博客发送到优快云博客网站上,那么对于我写的Blender 3D 建模方面的博文,里面有很多的图片。如果我要发布一篇 Blender 3D 建模的博文的话,图片要一张一张的上传,上传的速度有时也是很慢,整个发表一遍这样的博文,我光 上传图片 就要

AoboSir.com 1万+

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

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

001基于Python网站爬虫的设计与实现

1.1 课题背景网络爬虫,是一种按照一定的规则,自动的抓取万维网信息的程序或者脚本。另外一些不常使用的名字还有蚂蚁,自动索引,模拟程序或者蠕虫。网络检索功能起于互联网内容爆炸性发展所带来的对内容检索的需求。搜索引擎不断的发展,人们的需求也在不断的提高,网络信息搜索已经成为人们每天都要进行的内容.如何使搜索引擎能时刻满足人们的需求。最初的检索功能通过索引站的方式实现,而有了网络机器人。但是,这些通用性搜索引擎也存在着一定的局限性。

qq_1406299528的博客 2829

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

毕业设计001基于Python网站爬虫的设计与实现

1.1 课题背景网络爬虫,是一种按照一定的规则,自动的抓取万维网信息的程序或者脚本。另外一些不常使用的名字还有蚂蚁,自动索引,模拟程序或者蠕虫。网络检索功能起于互联网内容爆炸性发展所带来的对内容检索的需求。搜索引擎不断的发展,人们的需求也在不断的提高,网络信息搜索已经成为人们每天都要进行的内容.如何使搜索引擎能时刻满足人们的需求。最初的检索功能通过索引站的方式实现,而有了网络机器人。但是,这些通用性搜索引擎也存在着一定的局限性。

m0_50936939的博客 2893

python 爬虫实现前需要注意的地方

网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动的抓取万维网信息的程序或者脚本。另外一些不常使用的名字还有蚂蚁,自动索引,模拟程序或者蠕虫。 参看百度百科 http://note.sdo.com/u/wyatt/n/mbnUS~jpc4spnM00k001a5 最近

NN179的专栏 6825

python网络爬虫与信息提取

The Website is the API 掌握定向网络数据爬取和网页解析的基本能力 1.Requests库的入门 1.1 Requests库的安装和方法 requests库的7个主要方法 import requests r = requests.get("http://www.baidu.com") r.status_code 输出: 200 r.encoding = 'utf-8' r....

XXMRXXX的博客 878

【Python教程--从零基础到精通】001.初识Python

我们学习Python必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有阿里大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。编程语言是人与计算机进行交流的工具。Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。观看零基础学习视频,看视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。

m0_59236602的博客 949

Python实验1——网络爬虫及数据可视化

获取网页 def getHtml(stack_code): data = requests.get("http://quotes.money.163.com/trade/lsjysj_" + stack_code + ".html#06f01", headers={"user-agent": "Mozilla/5.0"}) # 获得一个请求得到的静态网页 return data.text 爬的网站是网易财经的股票历史交易记录。经过观察发现,不同股票历史交易记录的区

ZERO的博客 1万+

python网络爬虫之农大绩点计算器

最近在家无聊,正好在网上看到一份不错的python教程,于是就学起了python。python是动态语言且具有函数式编程的特点,相比C/C++、java这类静态语言,有很多不同并且很有意思的地方。在学习到教程的常用内建模块xml部分时,老师留下一份作业: 练习一下解析Yahoo的XML格式的天气预报,获取当天和最近几天的天气: http://weather.yahooa

叫我二巧 2513

python 爬虫text函数_通过三个函数了解Python网络爬虫

前言:最近在学习Python网络爬虫,在这里分享一下自己的学习成果,通过几个函数梳理下网络爬虫的过程,网络爬虫就是用自己的电脑去web服务器(另一台电脑)上下载东西,其中涉及到两个问题:(1)怎么让自己的电脑和web服务器连接(2)正常连接之后,怎么把想要的信息提取出来爬虫相关函数:def get_html_text(url): #解决第一个问题passdef get_info_list(htm...

weixin_39556590的博客 471

python新闻聚合_基于Python的新闻聚合系统网络爬虫研究

基于Python的新闻聚合系统网络爬虫研究左卫刚【摘要】摘要本研究旨在创建一个能够从不同页面布局中提取数据的开源爬虫,其中包括网络爬虫、API、网络爬虫调度器以及Socket服务器的实现等。使用Python语言开发网络爬虫,利用BeautifulSoup作为网络爬虫的Web提取工具,以Laravel为Web应用程序框架,PHP作为主要后端语言,承载CMS和API。网络爬虫可以通过利用用户创建的配置...

weixin_39772420的博客 559
上一篇: Python3 pip 解决问题: error: Unable to find vcvarsall.bat
下一篇: Python --- Scrapy 命令
AoboSir
博客等级 码龄10年 996粉丝 285原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值