粉丝1.7万获赞6.9万

school repair 是拍摄很常用的一个帕虫框架,安装它只需要康达 install school rep, 只要一号命令就能够安装上。那么通过这个框架呢?我们可以很简单的实现一个帕虫,比如抓取指定网站的内容和图片。快去试试吧。

这里是幺三零幺零幺,大家能看到我桌面吗?呃,刚刚呢,让大家安装一下对吧? 呃,安装之前呢,咱们简单先回顾一下啊,就是 scrapping 是一个什么样的框架,它是 使用 python 开发的,开发的主要进行数据采集的一个应用程序框架, 核心使用它来进行爬虫程序的快速开发。 由于了底层使用了 twisted 一步模块,所以在进行数据采集下载 实效率非常高。就这样一个东西啊,安装的时候呢,需要注意什么情况呢?乌斑图或者说 mikos 下了直接安装什么东西了,安装我们的 scrapping 就可以了, 就是在有完善的 python 环境的基础上 直接安装就可以了。但是 windows 下需要注意, windows 下注意安装分两步进行,分哪两步进行呢?第一步,先安装 scrappy, 安装 scribe 的手了,建议大家可以使用管理员身份用行就是管理员身份用行, cmd 窗 孔这样的情况呢,可以尽量避免出现一些呃,由于权限啊等等这样出现的问题,通过 pip instal scrappy 直接安装,或者说 easy install scrappy 安装就可以了。安装完成之后呢,我们还需要安装 win 三二,这是个什么东西呢? 因为盘中程序在 windows 里面操作的时候了,可可能会调用 windows 底层那些模块,所以说说了需要安装一个,需要安装一个配风三二模块, 安装这个模块呢,用于 scrapping 模块,可能调用温底层 操底层 c 操 c 库进行函数操作。那这个东西呢,同样通过配文三二,哎,是叫配文三二,这还是叫个叫什么文三二来着,我在这里呢给大家写了一下 pipe 文三二, pipe 文三二 这个东西啊,这个呢也要安装一下,安装成功之后呢,我们的程序才能正常执行,如果这个东西没有安装的话,程序 scrappy 操作没有任何问题,但是 scrappy 项目是用行不了的。说一下,如果 ps 注意,安装完 scrappy 之后,可以正常的进行 scrappy 项目的开发,但是用行在 windows 上用行项目会出现问题, 如果出现 when, 如果出现类似于 when ever 这样的问题, 请安装下面的模块,就是咱们这里的 win 三二模块。 ok, 这个安装完成之后,也就是大家刚刚做的一个操作,这个安装完成之后呢,第二步 项目开发,项目开发里面的了创建 scrappy 项目创建 scrappy 项目呢,通过执行命令,通过执行如下命令来创建 scrappy 项目,执行了一条什么样的命令呢?可以通过 scrappy starter project, my spider, 或者说后面了咱们就是 spider name 这条命令呢,通过 scrappy 命令 加上 starter project 选项,创建一个名称为 spider name。 爬虫项目,就这样一个意思,那我们在开发的过程中通过哪里开发了?在 p y charm 中, 直接用行工具中的 c, m d 终端窗口 执行如下命令,创建一个爬虫项目。 在这里给大家简单的先看一下,看完之后呢,说一下里面需要注意的问题啊, scrappy starter project, 然后呢就创建一个 my spider, 好吧,这里呢需要注意注意什么呢?关于终端窗口, mini 窗口和还有一个东西叫 share 窗口,这几个啦在不同的地方出现的意义不一样。 note 系统中有终端窗口,有命令窗口,他们都指带的是 cmd 窗口, ok, windows 里面呢? windows 的新系统中,比如说 win 十,它里面也有 shell 窗口。 shell 窗口呢,它指带的是 power shell, 在这个窗户里面可以执行常见的 linux meaning, 仅此而已。 那这个窗口在哪里找到呢?可以在我们鼠标螺到桌面的最左下角右键点击,这里是不是有个 window windows power 呀?点开 windows power, 大家就会发现弹出这样一个窗口,稍等一下啊, 大家看一下,这里是不是弹出一个这样深蓝色的窗口呀?里面呢,有 windows shell, 大家在这里可以执行 l s, 大家可以看一下 l s 命令呢,这个命令大家知道是在 呃 linux 面的命令对不对啊?在 windows 上本来就没有 l s 这个命令,但是在 powershell 这个窗口里面呢,就可以执行这个命令,来查看当前文件夹下的所有文件,这样能看明白吗? ok, 另外呢,我们终端窗口这里说一下啊,终端窗口呢,它有一个英文单词叫 tomel, 嗯, tomelow 是这样写的吗?来打开看一下, tomelow 是吧? n a l 是吧? tomelow 这个单词在其他系统里面也会出现,比如说乌白图系统中,这就是我们的 linux 或者 unix 系统了。好吧,在这样的系统里面呢,我们经常会提到终端,终端其实说的就是 shell, 在这样的系统里面说的就是 shell, 它指带的就是我们的 shell mini 窗口。 所以呢,大家在乌白图系统里面,如果搜 tomel 的话,就可以打打开试药窗口,这能看明白吗?然后在 mcos 系统里面了, michael s 系统里面呢,它同样呢也称之为终端,它同样打开呢是摄像窗口。 ok, 只有在我们的 windows 里面是不一样的。 windows 里面,咱们的终端窗口是命令窗口, c m b 窗口,也叫 p 处理命令窗口。 c m d 里面执行的命令了,也称之为批处理命令,就是批量处理的命令。 ok, 这个呢,有一个大概的印象就可以,那我们在 p y charm 里面了,运行 p r a charm 的终端, p i charm 的里面的终端窗口,执行下面的命令,我们先打开我们自己的项目,打开自己的项目之后呢,大家可以看到下面是不是有个 tomel 呀?这,以前的时候我们经常用 run, run 里面是不是用行的用行窗口呀?嗯, ra 是用行窗 口。 python ctrl, 这是 python 命令行窗口。大家看到这里是不是有三个尖角符号呀?呃,就三个,大于号。这是 python 的命令窗口,特名老师命令行窗口。 然后呢, cd 到 cd 到咱们的五点, make d i r dyson 零七 c d 代词,零七,这是不是创建了一个文件夹,并且进到一个新的文件夹里面了呀?呃,在这里给大家说一下啊,以后呢,大家在操作这些命令的时候,对于常见的命令了,不光要认识自己,还要会 写。可不能说等到面试的时候,人家说来列举一下你常见常经常使用的一些命令吧,如果说不会用这个就很尴尬了。 那进来之后呢,我们先创建第一个程序, scrappy, 当然我是已经安装好了的 scrappy start project my spider, 通过执行这行命令来在 dis 零七下面创建 my spider 爬虫项目。 ok, 回车稍作等待。 大家可以看到下面是不是说 new scrappy project my side 创建了一个 scribbage 项目叫 my side, 是 my spider 是吧? using tablet directory, 它使用了一个, 是不是模板的意思啊?他通过这个指定的指定的目录下面的东西创建了我们的项目模板。然后呢?项目在哪个地方呢?在 dis 零七下面有个 my spite, 看到了没有? 在这里呢,说 you can start your first spider with。 说你可以开启开始写你的第一个盘中程序,通过下面的命令先进到这个文件夹里面,然后通过执行 scrappy general spider example example to come。 这是通过命令直接创建一个盘中程序,当然我们第一个,因为我们是第一个程序,我们手工给大家创建一下,看一下有什么有什么操作方式。好吧, 创建好项目,人家提示的这条命令是通过命令自动创建爬树程序, ok, 自动创建了爬树程序,我们只需要修改一下就可以直接使用了,当然我们手工先操作一下。大家对于 爬出程序了有一个比较深刻的了解,我们在进行后续的操作,大家首先了先了解他的项目结构,这个项目结构了和我们摘购项目的项目结构是不是特别类似啊?在外面有个 maysbad, 里面是不是还有个 maysbad 啊?嗯,然后跟 maysbad 同级的, 大家注意跟买 spy 的同级呢?是不是有个 scrafty cfg 啊?打开 scrafty cfg, 大家在这里可以看到里面有个 setting settings, 有个 deploy settings, 什么意思呢?这是我们的项目设置文件,这这个配置用于指定我们盘中项目设置文件在哪个地方? ok, 这是指定详细设置文件的位置。 接下来 deploy。 deploy 什么意思呢?发布爬虫的时候会把这个项目发布到什么地方去?我们现在是 project, 叫 maxi 的,买 spy 的,是吧? 也可以指定一些 uid 纸啊,这些通过 uid 纸来调用爬虫子操作,各种各样的操作方式都有,这是项目配置文件。那 my spider 呢?是我们爬虫的核心模块,我们以后所有的开发都要在 my spider 下进行进行,在它里面呢? inlet 就不说了吧, items 里面是做什么的呢? defied the field for 什么什么乱七八糟的上面了。 defied here the models for you spider scrapped item 什么意思呢? the model 是什么模型的意思呀?说,我们在这里定义模型给你爬取的项目, 我们是不是爬取下来的数据就是爬取下来的各种各呃,各项数据啊,把我们各项数据了分装成 ittom 对象,在当前的这个类里面进行定义,也就是最后我们爬取了数据, 都是零散的数据,对吧?零散的数据要在这个文件里面把它组合成一个一个的对象。好吧,这是定义爬去数据组合成的对象类型的地方。 middlewear 是什么意思了? middlewear 是定义各种各样的中间键的地方,大家可以看到在一个 middlewear 里面了。 my spider middlewear, 这是一个我们自定义的中间键,是吧?它里面都有什么方法呢? from drawer this method is used by by scrappy to create your spider。 说这个函,这个函数呢,主要用来在你的 scratchy 在创建这个爬出程序的时候就去执行的一个东西,默认执行的 process spider input called called for each response that guns through the spider midway and in to the spider。 这是在什么时候调用了 response 开始响应数据的时候进行处理? process spider output。 大家可以看 process 是进程处理的意思,是吧? spider 是程序的意思,就是爬虫的意思。 process 处理爬虫 input 响应响应,进入程序的时候处理。 alt 返回数据给爬虫的时候进行处理。 exception, 当爬虫出现异常的时候执行的处理 request, 当请求开始执行的时候进行的处理。这是不是所有的中间键都会执行的一些东西啊? 就是当你在做什么事之前或者之后要执行的函数,是不是都在我们的中间键里面可以写啊?这是 mediever papa lies 是什么意思了?这里可以看到有一个 my papa lie, my spider popline 是一个简单的拍生类型,对不对啊?它什么的东西呢? define your item popline here don't forget to addo popline to the item popline setting。 啪啪啦一了,主要用来进行数据的最后一步的操作,就是我们那张画的这张图里面啪啪啦一是不是在这里啊? 最后一步进行数据数据的验证,重储等等这样的操作。那在定义的时候呢?我们这里定义好了自己的 popline 之后呢?要在 cit 配置文件里面有一个 itempoplines, 把我们的 popline 交给 scratchy, 它就知道说你定义了一个 papa line, 可以进行数据处理, ok, 如果我们不在 sentence 里面配置的话,这个 papa line 是无效的。这个当然后续的时候再说 sentence 呢,就是我们的设置文件, 项目设置文件,这里有包车内幕。然后呢, spider models 就是我们的当前的爬树模块,然后 new new spider model 是创建了一个新爬树模块,下面呢? robot text oba, 这什么意思了? robots text 什么意思啊?看聚焦, 我怎么听着这么陌生呢?什么叫聚焦?什么叫焦点?我搜一下淘宝,大家看一下 robot, 嗯, 哈哈哈哈,输入的格式不正确, 看一下下面这个就是 robos 协议。你们看看,这只是一个文本文件是吧?文本文件里面的 user a 证它,百度 spa, 它 允许谁爬去的?允许百度搜索的 article 允许你爬去。 o s s t m l 允许你爬去。 production 不允许了。 desert 老师不允许对吧?根木路允许吗?不允许,这是什么? 谷歌爬虫对不对啊?谷歌爬虫允许的东西就多了, article 允许, o s h t 庙允许, prodat 允许, spu 允许,店铺允许, oversee 允许,累死他允许,只有跟梦露不允许。太过分了,淘宝竟然只允许百度爬这两个, 然后人家谷歌游戏爬这么多,再往后并搜索对吧?并搜索是不是游戏也挺多的呀? article os html product s p u 店铺。哎呀, 看这是英文是吧,这好像拼音吧。所以说不要看那些说啊,谁谁谁从哪里出来的,或者说什么公司说就有多高大上。对于开发人员来说,你的公司再 low, 你的公司再高大上,开发的程序是一样的, 这是什么?三六零是吧?三六零呢?通用爬冲就是三六零,搜索用的爬冲,它只允许两 art 口号 o h o s h t m l, 这是什么呀?一搜一搜也只允许两,这是搜狗是吧?搜狗允许三个 底色,老师不允许。雅虎搜索允,允许的还比较多是吧?然后其他的全部都不允许。这,这是 robo 的协议吧,他意思说 robo 的协议没有 错误,里面了所有的协议格式是这样的。那 robo 的协议是用来做什么的?限制通用爬虫 不允许爬去就是现实。通用爬虫的爬去规则对不对啊?那我们 scrap 里面默认是不是遵循 robo 的协议啊?如果一旦遵循 robo 的协议,就会发生什么事,有一些数据不允许爬去了,所以我们在实际操作的时候,这这个会改成什么呀? false, 因为我们用 toscrippy 在开发的时候经常用于开发聚焦爬虫,聚焦爬虫就会忽略肉包的协议。 ok, 好了,再往下呢,大家看一下,里面有各种各样的配置选项。 default request hyder 了,什么意思啊? 请求头吧,我们请求头直接在这写一下,是不是在请求头里面就包含了呀,就不需要自己再设置了吧。 ok, 再往下 download middle wears 下载中间键 extensions 扩展 item pipelines 这个看懂了没有?如果我们自己写了 peplus 之后呢,一定要把这个注视放开, 放开之后把自己写的 papa line 写到这里,后面是一个零到一千的整数,表示他的优先级。 ok, 再往下呢,还有一系列其他的各种各样的设置,这个呢,后续的时候大家再看,现在大家知道我们通过手工,就是我们通过命令好创建了一个盘珠项目,他大概文件结构是什么样子了吗? 也就是我们在这里了创建好项目文件结构如下, 咱们尽量慢一点,争取大家一遍把这个东西就该学的都学会好吧。 my spider, 这是项目根目录, 里面呢,会有一个 spiders, 这是爬虫程序所在的目录,里面写各种各样的爬虫程序。 哎呀,这里还有个东西,上面是不还有个 my spy 的呀?嗯,咱们把这个写到下面吧。 上面这里了还有个 my spider, 这是爬虫模块儿,以后 的爬虫程序开发都在这个模块中。 ok, 和他同级的了。还有一个东西 和他同级的了,有一个 scrifi 点 c f g, 它是项目配置文件。这个 c f g 什么意思呢?它是 configure 的意思,是配置的意思。 ok, 其他的几个字母 c f g 在它里面。 item c p y, 这是采集的数据定义分装模型内的模块儿,也就是了我, 我们将采集的数据了定义成分装的模型内,是不是采集的数据就可以分装成对象了呀?这里面就是定义这种类型的模块。再往后呢,我们需要关注的是 piper nice d p y, 这是采集的数据最终呢,采集完成之后进行数据验证存储的模块。 再往后面呢? middle where step p y, 这个是中间键定义的模块儿,然后后面还有一个什么东西呢? sentenced p y, 这是项目设置模块,项目设置为 模块和配置文件,一定要分清楚,配置文件是用来配置信息的,设置模块是用来设置参数等等各种各样的数据的。好吧,这两个要分清楚。大概呢有这样几个。大概呢?有这样几个模块,大家可以看到 autumn, metalware, paradise, sentence, 包括 speed 是不是都有了呀? ok, 都有了之后 我们呢爬虫基本的 scratch 项目就创建完成了。 创建完成之后,下一步我们进行做什么操作呢?看一下啊,这是不是创建 scrappy 项目呀? 下一步就是我们即将要进入第三步开发爬虫程序。那在开发爬虫程序之前了,大家先把这个项目创建出来。 ok, 创建出来之后咱们进行下一步操作。

alright guys welcome to this video series of using scrappy to do web scraping and web crawling in this video we are going to be learning how to install the scrappy inside your computer if you are using an ide or a software lakes or blame text add a more nood back plus plus so for the purposes of this video i'm going to be assuming that you decided not to use piechum ide, but if you for some reason decide to use the piechum id you can always go back to the previous video piechum makes the whole process of installing and using pieton and scrappy a lot easier, but it's fine if you decide to use a blind text too so the first thing you need to do to install scrappy on your computer is obviously you must have python so you can just go to the official website of python and install the latest version of python in my case, python three point seven point one after you have installed python you can just go for your text editor of your choice in this case it's a sublime text so after you have installed sublime text it's gonna look somewhat like this so what i want you to do is create a new folder called scrappy tutorial just like i have if you want to follow along and then open that folder inside sub lime text after you have done that we are gonna follow a particular set of processes which i am going to paste over here so obviously the first process is done that you have already installed python and sublime text then the second process is actually to create a virtual environment now what is a virtual environment? and why do you need to install one? so what's your environment basically i select your project from the rest of the computer so for example if you install any kind of package inside your scrappy tutorial folder is not going to be installed in the rest of the computer and vice versa if you install some kind of package in the rest of the computer, then it's not going to be installed inside this crappy tutorial folder so for example if we install this scrappy package inside this scrappy tutorial folder with the virtual environment activated then scrappy is just going to be installed inside this scrappy tutorial folder and not in the rest of your computer this kind of useful to isolate your working environment from the rest of the computer now the process of installing a virtual environment and creating a virtual environment is pretty easy you just need to follow these steps over here, so in our case i'm using windows, so i'm going to be opening up my command front because you may be using linux or mac then you can open up your terminal so what you need to do is you need to install this package? noon as pep env or pep environment so what i'm going to do is i'm just going to write pep install and pep env and just press enter now already half ppne install inside my computer so it's just going to show that requirement already satisfied, but when you write it on your computer if you don't have tip env already installed it's going to install it after that it says create a virtual environment by typing in virtual env and then full stop so first you need to go to the project folder in our case it's crappy tutorial and this project folder is inside my e drive and i'm just going to change my directory by writing cd, which stands for change directory, i'm just gonna write the name of my scrappy tutorial so i'm just gonna write scrappy and scrappy tutorial and i'm gonna press enter after you're inside your project folder as you can see it's totally empty right now you just need to create a virtual environment by typing in botule env and then full stop so i'm just going to write watch your env full stop press enter and it's going to create an environment for us you just have to wait for a couple of minutes after the virtual environment has been created you need to activate the virtual environment now if you are using windows, you can just paste this dots backslash scripts backslash activate, but if you are using lenux and mac you need to type this bin activate on your terminal and because i'm using windows so i'm just gonna copy this from over here and i'm gonna paste this on my terminal and make sure that you write this this code of dot scripts and activate inside the folder that you have created a virtual environment in so i've created the virtual environment inside my scrabby tutorials and fold us i'm gonna base this over here and press inter and as you can see there are these curly braces over here, not curly braces just braces over here the brackets over here and students crappy tutorial over here and this means that our virtual environment has been properly activated now if we write something like bit freeze over here, you'll be able to see that we don't have any packages inside on scrappy tutorial virtual environment what if freeze does it basically shows what kind of packages are inside your virtual environment and right now there are no packages so let's install scrappy inside our scrappy tutorial folder after this virtual environment has been activated as you can see this is the third step, so how do you install scrappy? it's pretty easy, just right pep install scrappy and this scrappy package is going to install other packages so this might take a little bit of more time depending on the speed of your internet so i'm just going to wait for this installation to be completed so after scrappy has been installed we can just type in piff freeze again to see what kind of packages are installed inside a scrappy tutorial folder so now you can see that scrappy is installed, but not just scrappy a lot of other packages are installed with scrappy, but obviously scrappy as you can see the one point five point one version is also installed, but it requires other packages so that is why scrappy has automatically installed other packages for you now what i want to do is i want to create a project now, but before that i just want to show you the project structure inside this crappy tutorial folder over here now if you open it up it includes the has a lot of beard folders like include lip scripts and t c l now all of these folders are actually because of the virtual environment to don't worry about them they are not the folders of your scrappy project, but don't delete them because because of these folders of virtual environment has been created inside the scrappy tutorial folder, but just don't get worried about it like one of these folders now we are going to be starting a project inside scrappy and that is the most beautiful part of scrappy you can just write scrappy over here and then you can just start the project and we are going to be in the next couple of videos we are going to be creating a quote scrapper so i'm just gonna be lighting quote tutorial over here tutorial over here and pressing into now what this will do is that it will create a project structure for us and it saves you can start your first spider web cd core tutorial we don't need to do that because we are using supplying text and now if we open up artwork tutorial folder as you can see it has a lot of files installed in it now, we are going to go through this project structure in the next video, but for right now we have successfully installed scrappy inside our computer with sublime text now just for the purposes of the future videos i'm going to be using by champ so my project structure is going to be like this just like in sublime text this not a lot of difference and instead of using command prompt or terminal i'm going to be using the terminal that is inside by jump from over here now the virtual environment inside pie charm is actually over here it has been created for us by pie charm so you don't need to create a virtual environment in pie charm, but it doesn't matter because we have created a virtual environment for us by using pip e and v so guys this is pretty much it for this video from the next video we are going to be creating a vet scrape up for our first project that is scraping quartz of authors from a website, so i'll see you in the next video。

all right you beautiful webscripts and bites on developers in this video we are going to be installing scrappy now this video and the next video are going to be about installing scrappy and there are a little bit different videos because in this video we are going to be using a software or an ide known as by chum and ide is basically a software where you can write code? i've been using pie charm for a really long time and it's just really easy to write code on pie charm so i'm going to be using that so if you want to follow completely along i'll highly recommend you download a version of pie charm now pie jump has two versions a professional version and a community version you can download both of them they both work totally fine i'm going to be using a professional version which has a thirty day trial so if you want to use that be free now what if you don't want to use pie jump and you want to use a software like sublime atom or maybe notepad plus plus don't worry if you want to use that that i'm going to be covering in the next video where you can use any software? you want as an ide and it's going to be a little bit different from what we are going to be talking about in this video? so if you have any other software that you want to install then just go to the next video but if you want to just install by charm then you can carry on with this video so what first thing you need to do is you need to obviously install python if you don't have it installed currently the latest version is python three points and point one then go to this python page that is jet brain spy charm download and then just download the community of a professional version and after downloading just start up your pie charm and it should somewhat look like this they just go to file create a new project, and just give it the name of the new project over here, and if you want to totally follow along you can just call it scrappy tutorial just like i have and it will create a new project for you called scrappy tutorial and the cool thing about by charm is that it will also create a virtual environment for you and this virtual environment is called v e and v as you can see on the left hand side so if you're not using pie charm i'm going to be telling you how to manually create this virtual environment in the next video, but if you're using pie charm this is automatically created for you now what is virtual environment? so virtual environment is basically an isolated unit, so for your project? so what is an isolated unit for your project? so for example let's say we install scrappy inside this scrappy tutorial project folder then this scrappy package won't be installed in the rest of your computer this scrappy project will only be installed in this tutorial project folder so your rest of your computer won't be affected by whatever, we do inside this project so this project basically adds acts like an isolated unit now that we have created a basic project what we can do is that we can just go to settings and we can just install scrappy by going to project onto pritter then clicking on this plus icon and just searching for scrappy and then we can just click on scrappy and click on installed package now this is not only going to install scrappy, but it's also going to install other packages that scrappy requires so it's going to take a little bit of time so make sure you wait a couple of minutes for this installation to be completed now after this crappy has finished installing it will kind of look like this and if you close this window you will see all of these packets have been in installed and scrappy along with all of the other packages has also been installed now you can just click on ok and python will just take a second to make sure that your project of scrappy as running properly now depending on the speed of your pie charm it might take a little bit more time to build up the skeleton, but after it has completed all the process over here you can start building the project by clicking on the termil, option over here and this will dedically take you inside your scrappy tutorial project folder with v a and v that is your virtual environment activated now over here you can just start the project by writing scrappy and then start project and i'm just gonna call the project as quote tutorial because we are going to be working on a quote website to extract or web scrape a quote website so i'm just gonna call it tutorial and press enter and this is going to make sure that the project structure required by the scrappy is actually created inside the scrapey tutorial window so it's as sage you can start with your first spider that is your first python program or web scraping with cd quart tutorial and then this scrapege and spider example example dot com so now if you go this scrapey tutorial folder and open it up you can see it has this folder called quote tutorial and if we open it up a little bit more you can see all of these files inside a project now we are going to discuss what all of these files are in the next video not in this video and yeah so we'll discuss all of these files in the next video and if you haven't installed by chomp make sure that you see the next video where we'll be learning how to install scrap inside a different ide like sub sublime text or atom or notepad plus plus now if i've already installed pie jump you can just directly jump to the video where i'll be explaining this project structure so i'll see you over there。

好,我们这节课说一下这个 splus 如何跟我们这个 screpe 集合那个结合啊?那么如果说你要想用这个 splus 跟那个 screpe 去结结合呢?你需要去做什么事情呢?来看一眼, 首先啊,你要去在你的这个赛厅里面去配置一个 splus 的 ul 啊, ul 也就是告诉他我们那个 splus 那个服务在哪, 那么要不啊,告诉他这个东西,然后呢,你还要去用什么样?弄一个下载的中间键给人家加上去,那这里边是为什么是要用它呢?是因为我们去下载的时候呢,应该是通过 spos 去加载了,对不对啊?所以说他说要加一些,加一些下载的中间键,然后还有什么呀?还有一个叫做 spos 的一个堵飞,堵飞 这个东西吧,其实这个东西是干什么的?无非就是驱虫的一个作用啊,就是一个驱虫的,因为我们之前那个 super ipad 里边它有自带的一个驱虫的功能,对不对啊?那么你用 spa 式以后呢,应该也有个驱虫的功能,所以说的话,你要把这给他加上去啊,把这句话也加上去,然后还有什么呀?还有这个具体的过滤的这个类 啊,也给他加上去就可以了啊,还有消息对列,那么我们只需要把这几个钱加上去以后啊, ok, 那么这个东西就可以去使用了,那么在使用之前的话呢,你要是要使用他这里边的一个相应的一些模块啊,一些相应模块,那这个模块叫什么呢?叫做 sprepe sprush 啊,加上这个东西就 ok 了,所以说你要想使用他的话呢,你得先把这个给他装进去就 ok 了啊? ok, 那么我们知道这些东西以后,然后剩下的我们就是来敲个代码,比如说我们现在写一个 是 party, 然后再加一根,一个跟 spader, 然后瓜子 啊,创建一个爬虫, 创建了爬虫,这是我们之前去发送的那种请求,那么我们这块地要发送给谁呢?要发送给他克罗伊克罗斯 啊,那么这一块的话我们直接就可以获取响应了。瑞斯棒斯点什么呀?就是普任他 response。 第二 xpa 啊,不, xpass tips 吧?对,然后我们就能在这就能看见那个文本了,这是我们原来写的那种套路,是不是啊?啊?但是现在我们要改了,要改了。改成什么样?叫做 furm, 个 spa 是音炮的,然后有一个 spa 是 request 啊,为什么要用?为什么要用它呢?我们之前用的是这个 request, 是不是啊?那是人家我们这个 super 里面默认那个,现在我们要用这个 spos 发送全球,所以说我们要使用这个 啊类,那么要使用这个类的话呢?在这呢,斯达斯达 us 呢?他默认发送的还是那个瑞筷子的吧,所以说咱们要改,怎么改呢?我们要改成这个让他去发送啊,所以说我们这要写什么?迪范的,然后一个斯达达瑞筷子的,然后压的一个什么呀?死不拉?是, 是快死的。然后把我们的 ul 扔进去啊,我把这 ul 给他摘出来吧, you up 复制过来,那这个东西就没用了。那么我们把 us 扔进去,扔进去以后呢?然后我们这个地方再去发送请求就可以了。 这跟我们别的写法都一样,其实就是无非换了个类而已啊,换了一个类而已,那么这样写完了以后呢?然后我们相当于是这一块改完了,改完了以后,然后我们这个塞停要记得要去加一些相应的信息,然后告诉他我们的 splus 在哪,那这个地方的话是 uv 啊,就一块改一下吧, 这有吗? start, 嗯, false, 然后我们 加的是他的地址,地址的话我们给他靠过来这一句 surplus ul, 这个是告诉他我们的 splus 是在哪啊?说白了就是让他让哪个 splus 继续加载啊。 ok, 那有他以后,然后我们再把下载中文件给他拿过来, 这个下载中间我们找到他 就不用他了。 ok, 有这个以后还有一个什么呀? spr 式的,一个过滤器拿过来, 然后还有两个对列,过滤器的内还有个对列。 ok, 那么这有了以后呢?然后我们就可以去使用了,使用 的话呢,然后我们直接去启动我们的项目,试一下大的,然后 from socrappy, 然后里边 cma 啊, sq 的,然后 socrapy 烤肉, 然后瓜子来我们看下这个效果啊,就是说在这去右心右键运行一下, 运行以后他这边会出现这些东西,首先上面是加载这些日志,我们不用管他,然后呢我们再看一下他底下, 底下的话呢,这有这个刀态吧,这说明已经拿到内容了,拿到内容以后,然后你会发现这底下这个内容好像是不齐的,其实跟我们一开始没有位置的时候是差不太多的,对不对啊?那面的这种情况怎么办呢? 我们只需要让他去喂他一下就可以了,那么这个地方我们怎么去呢?走呢?在这个地方我们之间写在这的时候,然后怎么办呢?我在这去加上一个东西,叫做 没有阿克斯,阿克斯,然后这里边给什么样?给他一个 k, k 的话就是喂他,然后呢?让他等待,等待疫苗啊,我们之前等待疫苗好像就出来了,是吧?啊?然后试一下效果, 等一秒,然后这时候我们就看内容,看吧,啊,内容就出来了啊, ok, 那么这是相当于是我们使用了哪种样的方式呢?相当于我们使用的是 spa, 是第一种吧,叫做 rander 啊,假日奇妙那个东西,是不是啊?还有一个就是什么呀?我们要去使用的是那个叫做他的路挂代码那种样的方式, sq 的那种方式,那那种样的方式应该怎么去使用的话呢?我们来再创建一个啊,我再复制一个吧, 瓜子二,嗯,就写改成二就行了。然后这时候怎么办呢?我们依然去使用这个 sparts 这个筷子去发送请求,但是这时候我们要去加一个东西,加一个这个撸啊, so, 撸啊,代码啊,我就写撸啊吧。嗯 啊,那这块代码不知道是怎么去写啊?我们去找。 嗯 嗯,不是百度哎,撤了 幺九二的,打开我们这个服务板,是吧?在这服务这看, 直接把它敲过来就可以了啊,这东西不会去写的话,没关系,我们直接敲敲改改就是我们的了。然后我们这个为什么呀?首先把这个东西,这个这个 加点进度的这个统计图,不要,图片不要,我们只要一个 at 妙就可以了,是不是啊?干掉它啊?有了,有了以后呢?然后上面这些东西呢啊,我们就可以搞定了,复制过来, ok, 那么这有了以后呢?然后我们再就是什么呀?我们这个 ul 还用它先去试试看行不行?然后呢我们这 weight 呢也用用不到了,因为我们这 we 相当于是我们在这去给他执行了具体的撸啊代码,去执行的那个等待给他赶上一秒,然后还有什么呢?我们这需要加个东西叫做,呃, ndopot, 那么这个东西相当于是我们要再改那个模式,改成 sq 的 escute 啊,这个单词是什么东西呢?就是我们之前是这个另一种解决方式啊,那种解决方式的话,我们把有段云打开看一眼, 哎,出来 这是实用, 那么我们之间使用那个解析方式之后,我们用的是这个,是吧?啊,这回我们使用 sq 的 sesecute 这个,那么我们这写的就是这个单词,应该是 e s e c u t e 啊,就这个玩意,那么有了它以后呢?然后我们再去运行一下我们这个代码,看下效果是什么样子的啊?瓜子二,然后呢再去运行走 走,那么这过去以后呢?然后看他的代码是 拒绝了又又拒绝了, hcp 扣的 is not, 不被允许又不被允许了,那怎么办呢?我们去少写一个东西,少写一个路霸代码的东西,那么我们这再需要加个什么呀?阿克斯, 告诉他我们的撸啊代码在哪,那我们的撸啊代码这个 key 呢?这个东西这儿那个 key 就是撸啊,呃, sauce s o u i c e 啊,撸啊臊子,那这个撸啊臊子跟我们之间写的这个单词应该是一样的,这这个看到吗?啊,应该是一样的啊, 要复制过来,有了他以后呢?然后我们在这去后边再加上我们的什么路过代码码号,然后路过, ok, 然后这块香菜是补好了,然后我们再看 看这代码啊,我这这下载了好多样式啊,这 这不有价格什么之类的吗?看到吗?啊?这样就加载出来了,说白了就是什么呀?我们 刚才是没有告诉他我们的卢马,但卢马在哪?要执行谁,我们虽说把这个解析的方式给他改了,但是没告诉人在哪,谁要执行谁,所以说他一直直接访问了啊, ok, 那么这一块的话呢,要注意一点,就是什么呀?这个阿克斯这块,这个阿克斯是他这里面自带的一 一个参数,参数里边呢,然后有什么撸啊,还有什么别的一些相应参数,像这里边这个参数的话呢?呃,我们可以在哪去找呢?可以在他的官网里边这个文档里边,这有个刀挺门的,看到吗?点他以后,点他以后呢?然后这里边,哎,怎么打不开呢? 啊?有了啊,那这里边的话呢,会有一些相应的解析方式,那么解析方式的话像什么? randomhml 还是 random pnj 啊?还有 jpg e 的,还有 h a 啊,杰森啊, sq 的啊,这是好多解析方式,那么我们说了的就是这个啊,还有这个这个啊,其实用最多的就是这两 啊,这个是相当于说我们 splash 的快速里边默认的一种啊,默认的一种,那有的一些相应需求满足不了的时候,你就需要自己写入化代码,那么就用这个 sq 的就可以了,那我们比如说我们点开 sq 的里边,然后 他这里边有什么参数呢?嗯,看了吗?啊?罗斯特在这写的,还有什么汤姆奥汤,汤姆奥团,还有什么允许的域名啊啊?代理,还有什么之类的?还有这个过滤啊,好多就是这些参数的话,你都可以在里面去找到 啊。 ok。 那么这是这一块相当于是注意点就是什么呀?如果说你要想去 用我们 spa 使跟 spap 结合就橄榄了,把塞进里边给他敲几个东西就过来。行了,首先 把 ui 告诉他,然后告加上个下载中间键,然后再加上一个嗯, spa 的中间键,然后再加上两个类就可以了,一个是 过滤的类,还有一个对列的类啊,两个类就 ok 了。超,那么这两个搞定了以后,然后剩下的就没事了,然后剩下的就是我们把请求给他改成 spap 啊,不是那个死 splus, 快死这个就可以了啊, ok。

我们接着往下看,就我们讲最后一个文件,就是 settings 文件了,这 settings 文件它就是对前置的一些设置,因为我们已经讲完了这个所有的核心代码。其实已经讲完了 这个文件呢,就是比如说一些请求,并发量一些设置。首先第一个是否遵循这个机器人行,因为每个网站呢,他本身有一个,他的根目录下有一个 robos 点 ts 的文件,这个文件就是 是否允许那这个我们爬取,如果你遵守他的协议的话,那我们就什么内容都爬取不了,所以说一般我们一上来就要把它改成 boss。 之后我们再往下看啊,看到下面这个 concorn the request 他已注册掉了,当然这个地方他已经写了默认是十六啊,十六还太还是太大了,我们还是搞小一点, 我们初学者可以搞个搞个四吧,康康愉快的。就是每秒的请求最大允许取多少个请求,然后下面他结合下面这个登录的类,也就是下载延迟,我们 简单搞一个零点三吧,这两个一般结合用啊,恰到延迟,你可以大概理解为就是说每隔零点三秒出了一个请求 之后我们再往下看呢。还有就是关于这个默认性球头啊,我们给一个吧,比如我们给一个 ucra 键,它,不然的话,你不给的话,它的 ucra 键呢?就是我们 scrapping, 那这也太好反爬了, 别人一检查就知道你是 scrapping, 直接给你拦这个拦截了。所以说我们还要尊重一下别人,找个最起码 搞个 u c a 键的,这个东西可以随便粘贴复制一个就不会了。之后我们再往下看,然后是 item 拍 plus, 这个这个也要打开啊,这个就是, 这是起什么作用呢?这就是我们这个 pipeline, 就是我们这个存存储注意这个类它的开关, 因为我们这个文件它可以定义多个 pipeline, 也就是说我们把可以把这个图片存取到多个地方,比如说我们本地,我们这个类似存到本地,我可以在下面再定义一个, 呃,这个拍不 line, 同样也是定义这个 process 以及也就是这个函数,这函数,这这之间的函数是这个造型啊,这中间是我定义我们这个逻辑,然后我们在下面再写一个,嗯,比如说远端服务器一个之后我们就可以 在这个地方把这两个全部打开,照着照这个形式,前面是一样的,后面就是我们自定的另一个类,然后再给个数字打开,这样的话我我们就可以把这个这两个拍完了,同时启用,那么他就会同时在本地和远灯都来一份, 就是这个意思,这个数字呢就是代表了这个当前这个类的优先计,数字越小他就愿意优先处理,就这个含义。 嗯,这个 settings 主要就是这么个几个文件。最后呢我们再讲一下啊, 怎么启动这个爬虫,其实这个爬虫两种方式,其实准确来说的话,总统,总统来说其实就是一种方式,它其实就是用 scrapby crow, 这前面两个单词都是固定写法, 然后后面就是接一个我们要 pass 的这个我们的爬虫名的名,爬虫的名字,比如说我们 beyond 的话,这个地方我们之前跟他讲关于他的名字就是这个 name, 也就是 beyond, 这样的话我们就可以启用这个爬冲了,当然是我们要这个在哪个地方打开这个终端呢?要在我们这个当前这个路径下,就是我们这个顶端路径下,我们直接右键, 然后在中单中打开,这样就我们把这个这一行 mini 输进去就可以了,这样就可以启用这整个 part。 第二种方式,嗯, 跟他差不多,其实他只不过是请给了一个文件来请,不然的话我每次都要输中单命,比较麻烦。所以说我们这个地方给了一个文件,怎么给呢?就是说也是在我们的路径下直接右键 建新建一个拍摄文件,比如说我起一个嘛,起名一个叫 start, 然后啊我已经创建完了 啊,这个地方直接把这个 from scrapping part semi line, 然后呢再至利用 semi line excuse, 然后同样也是同样的 meaning, 看到吗? 之后我们其实运用这个文件运行这个文件,其实他运行的还是调了个中单,这样就可以爬取了,我们来看一下结果啊。首先我们来看一下我们的桌面,他是没有那个 啊,我们这个爬虫这个路径的名字,比如我们上集跟你说了在拍 blind 定义这个我们文件存储的路径,我们是在桌面儿的这个彼岸文件夹,我桌面儿现在已经没有彼岸,没有彼岸,我们来启动一下, 我启动完以后他就会在桌面生成一个这个文件夹,然后我们打开看一下里面的文件,里面的文件已经在爬取,我们可以看到其实在这个终端这个输出这个地方也可以看到他已经在抓取,已经在不停的跳动。 我们再来看这个问题啊,它实时的一些下载,我们看左下角速度还可以,三十一、三十二、三十三、三十七这些跳的还是可以的,比你 request 的库要快多了。 然后我们再来看一下,其实如果你会的话,其实可以把这个调大一点,可以这个 concone 的与快死以及当中的几类你熟练的情况下再调大一点。你初始学学习的时候还是尽量调小,比如你调个八或者十六, 当这个 delete 可以再调小一点,别搞零点一,他会更快啊。好,这样我们就讲到这里。

给我足量数据,我将挖掘未来。大家好,我是江子。呃,我们今天用这个四块币框架,前面不是讲爬虫了吗?爬虫讲了一部分,对吧? 今天呢我们就用 vip 框架啊,简单的去爬取一些内容,爬取的内容还是和我们前面爬取内容是一样,我们还去爬取某电影网站的这个,呃, 排行榜啊,某电影网站的排行榜,大家一看看到这个 ufo 大家就能就能明白,对吧?那我们主要是学习一下这个快递这个框架怎么用这是,呃,这个不算爬虫当中最经典的一个框架,好吧, 当我们我们打开这个彩笔之后,我们之前的这个爬窗视频,咱们之前讲过他们具体都是什么意思,比如 ct 是设置的意思,这个这个 呃拍不拉意思是,呃管道的意思,呃弥德威是这个中间线的意思,这个 it 是这个,呃我们的这个队列的意思, iphone 一个队列的意思,或者我们需要具体信息的意思,对吧?然后,嗯, spa 的意思是这个爬虫的意思。 那么我们整个啊,我们整个在这个框架当中啊,不同的文件啊,不同的文件起到了一个不同的意义,这里面是一个文件夹, 我们之前有说过,比如 c 田里面主要是一个设置的意思,我们去设置与我们这个项目有关的一些内容,然后管道的话,呃是去存储我们 查取下来的一些信息,按照我们想要的内容存储,中间键是去更改我们一些,比如说这个啊,请求投啊 啊等等去更改一些信息的时候使用的啊。然后 it 是我们想要爬取什么样的信息 在这里去设置一下,那当然了,这里面最核心的就是 spa, 对吧? spa 是就是我们爬虫的核心,我们以什么样的逻辑把它爬取下来啊?最终我们以什么样的逻辑给到谁?最终我们需要什么, 对吧? ok, 呃,整个这个我,我曾经跑过,我曾经跑过之后这个后来被封了,我们再跑一跑试试。啊? 啊?那我简单说一下,我们都需要去做些什么?对于这样一个爬虫都需要做些什么?第一个座位我们要去配置下 ct, ct 的话我们把这个 uca 卷,因为我们打开,我们看到很多他不都是已经注视过了吗?那我们需要把这个呃嗨的词这一块 需要给他打开,并且把我们的这个有谁准备配置进来,或者说你在这个嗨的上面还有一个嗨的,是吧?或者在那个地方配置也可以,对吧? 我我我一时半会,一时半会,我们不不管他,我就在这配置就行。然后后面的话,我因为我们要把这个数据存储起来,所以说我们配置一个管道的这个 管道的信息, ok 啊,那整个 ct 里面其他的我们就不要再动了啊,其他的还是保持原有的状态, 然后我们来写什么?我们要爬取的目标是这个内容吗?这个电影媒电影名字吗?对吧?所以说我们要在这个,呃,这个中间的这个 x i m 当中,我们去配置一下我们的这个,呃,我们需要得 道的信息,开通内啊,开通内幕之后,这就是我们需要得到的信息。然后呢?我们由于我们是要把它存到管道里面啊,由于我们是要把它存到管道里面,所以我们需要去把这个管道给设置一下,我们需要一个管道类, 管道类里面我们默认去打开 d 盘下的呃,被称一的 tst 文档啊,以写入的方,以写入的方式打开这个 ut 八的模式进行编码。然后呢我们去去在这个爱当中去找到艾特姆这个开头内容里面,然后一点一点的把它给写入进来,最后我们把它给关闭,然后返回艾特 啊,这就是我们整个从艾特当中去把内容写进我们的这个 塞尔啊,写进我们 bate 一点 tst 这个文档当中,那么这些都是配合使用的啊。那么最核心的当然就是 spadespard, 我们去看到啊, spard, 我们去看到,你看我们仍然前面这几个是没有,呃,是, 呃不能空的,对吧?我们的这个,呃整个的这个爬虫的名字是什么?这个是爬虫的入口,一会我们启动的时候,你看我们需要把它打出来的, 对吧?这是爬虫的入口,不能少。那么另外的话,我们允许仿,我们允许爬取的域名是什么,对吧?这是我们允许爬取的域名之后我们开始的 url 是什么? 这是我们需要去做的,这些是最基础的属性,我们不能不能空缺,对吧?然后下面就是我们处理响应的一个过程, 你会发现处理响应的过程和我们之前学爬虫处理响应几乎是一样的,对吧?首先我们先呃 把他给请求回来了,到这一步就已经把他给请求回来了,请求回来以后我们怎么样去解析他,对吧?因此我们也会在这个管理当中专门有一个 史莱特,史莱特是用于数据提取的,因此我们去做了一个史莱特泪,我把这个胖啊做成一个史莱特泪,我们给了他一个空的列表来存放我们的这个艾特,艾特姆,对吧?给他一个空的列表去存放艾特姆,然后我们就去用插帕去的方式啊, 我们用叉叉去的方式提取到了我们这个电影的我们这个电影的这个名字,而具体的叉叉是怎么样提取?我们之前的视频当中 有非常的简单相,非常的简单啊,我们就按照路径叉帕去,我们就按照路径一步一步的去提取出来就可以了啊,前面的视频当中有啊,大家可以去向前翻一翻爬虫,基本我已经全部讲完了,好吧,那么 呃,然后我们去做了一个放循环,放循环是什么?我们美,我们从艾特,我们从胎头当中啊,我们从胎头当中拿出一个来,呃,这个,呃,把它,把它这个 呃拿出这个值来,把它加到我们的这个列表当中,对吧?最终的话,我们的这个我们想要得到的信息就在这个列表当中,把这个列表付给这个信息,然后我们返还艾特。那么整个程序跑线来 来的情况下啊,整个程序跑下来的情况下,我看一眼啊啊,我们是可以,我们现在是没有让没有让他绝对的走起来啊,没有让他绝对的走起来,你看我们已经,我们已经可以找到这个第一个电影的名字了,那在我们的这个,呃, 在我们这个文件夹里面有个 x e, 他已经给我们写录进来了啊,如果我们想要想让他继续走的情况下,其实我们可以用另外一个方法,然后把它循环起来走,我们现在只是把他的第一个信息给他扒取下来,做一个演示即可。 好吧,好了,如果你想要去学习这个派森,比如说派森爬虫、派森外吧,派森数据分析等方面的内容,请关注我, 私信秘密。私信秘密吧。 私信你, 我会把相关的介绍发给你。呃,我的培训简单 有效,已经成功开始不是两,开设了两期 周末班,你值得拥有, 为自己的未来 好了。呃,就说这么多,今天的视频就到这里,我们下期见。拜拜。
