首页 文章 精选 留言 我的

精选列表

搜索[搜索引擎平台],共10000篇文章
优秀的个人博客,低调大师

运维监控平台之zabbix详解1

本来是想一篇文章介绍完的,写着写着发现篇幅太长,所以决定还是分两篇来介绍,本次软件所用的版本信息如下(基于LNMP环境),操作系统centos6.7 nginx-1.6.3.tar.gz php-5.6.24.tar.gz mysql-5.5.49-linux2.6-x86_64.tar.gz zabbix-3.0.4.tar.gz (zabbix-3以上版本之支持php5.4以上环境) LNMP环境搭建不再这里说明了,如果不懂的看本人之前写的nginx+php,这里简单介绍下php编译 [root@centos02tools]#wgethttp://cn2.php.net/distributions/php-5.6.24.tar.gz [root@centos02tools]#tarxfphp-5.6.24.tar.gz [root@centos02tools]#cdphp-5.6.24 [root@centos02php-5.6.24]#./configure\ >--prefix=/application/php5.6.24\ >--with-mysql=/application/mysql\ >--with-pdo-mysql=mysqlnd--with-mysqli=mysqlnd >--with-iconv-dir=/usr/local/libiconv\ >--with-freetype-dir\ >--with-jpeg-dir\ >--with-png-dir\ >--with-zlib\ >--with-libxml-dir=/usr\ >--enable-xml\ >--disable-rpath\ >--enable-safe-mode\ >--enable-bcmath\ >--enable-shmop\ >--enable-sysvsem\ >--enable-inline-optimization\ >--with-curl\ >--with-curlwrappers\ >--enable-mbregex\ >--enable-fpm\ >--enable-mbstring\ >--with-mcrypt\ >--with-gd\ >--enable-gd-native-ttf\ >--with-openssl\ >--with-mhash\ >--enable-pcntl\ >--enable-sockets\ >--with-xmlrpc\ >--enable-zip\ >--enable-soap\ >--enable-short-tags\ >--enable-zend-multibyte\ >--enable-static\ >--with-xsl\ >--with-fpm-user=nginx\ >--with-fpm-group=nginx\ >--enable-ftp >--with-gettext Generatingfiles configure:creating./config.status creatingmain/internal_functions.c creatingmain/internal_functions_cli.c +--------------------------------------------------------------------+ |License:| |ThissoftwareissubjecttothePHPLicense,availableinthis| |distributioninthefileLICENSE.Bycontinuingthisinstallation| |process,youareboundbythetermsofthislicenseagreement.| |Ifyoudonotagreewiththetermsofthislicense,youmustabort| |theinstallationprocessatthispoint.| +--------------------------------------------------------------------+ ThankyouforusingPHP. config.status:creatingphp5.spec config.status:creatingmain/build-defs.h config.status:creatingscripts/phpize config.status:creatingscripts/man1/phpize.1 config.status:creatingscripts/php-config config.status:creatingscripts/man1/php-config.1 config.status:creatingsapi/cli/php.1 config.status:creatingsapi/fpm/php-fpm.conf config.status:creatingsapi/fpm/init.d.php-fpm config.status:creatingsapi/fpm/php-fpm.service config.status:creatingsapi/fpm/php-fpm.8 config.status:creatingsapi/fpm/status.html config.status:creatingsapi/cgi/php-cgi.1 config.status:creatingext/phar/phar.1 config.status:creatingext/phar/phar.phar.1 config.status:creatingmain/php_config.h config.status:executingdefaultcommands configure:WARNING:unrecognizedoptions:--enable-safe-mode,--with-curlwrappers,--enable-zend-multibyte 编译过程截图如下 [root@centos02application]#ln-s/application/mysql/lib/libmysqlclient.so.18/usr/lib64/ [root@centos02application]#touchext/phar/phar.phar [root@centos02application]#make&&makeinstall Buildcomplete. Don'tforgettorun'maketest'. Installingsharedextensions:/application/php5.6.24/lib/php/extensions/no-debug-non-zts-20131226/ InstallingPHPCLIbinary:/application/php5.6.24/bin/ InstallingPHPCLImanpage:/application/php5.6.24/php/man/man1/ InstallingPHPFPMbinary:/application/php5.6.24/sbin/ InstallingPHPFPMconfig:/application/php5.6.24/etc/ InstallingPHPFPMmanpage:/application/php5.6.24/php/man/man8/ InstallingPHPFPMstatuspage:/application/php5.6.24/php/php/fpm/ InstallingPHPCGIbinary:/application/php5.6.24/bin/ InstallingPHPCGImanpage:/application/php5.6.24/php/man/man1/ Installingbuildenvironment:/application/php5.6.24/lib/php/build/ Installingheaderfiles:/application/php5.6.24/include/php/ Installinghelperprograms:/application/php5.6.24/bin/ program:phpize program:php-config Installingmanpages:/application/php5.6.24/php/man/man1/ page:phpize.1 page:php-config.1 InstallingPEARenvironment:/application/php5.6.24/lib/php/ [PEAR]Archive_Tar-installed:1.4.0 [PEAR]Console_Getopt-installed:1.4.1 [PEAR]Structures_Graph-installed:1.1.1 [PEAR]XML_Util-installed:1.3.0 [PEAR]PEAR-installed:1.10.1 WrotePEARsystemconfigfileat:/application/php5.6.24/etc/pear.conf Youmaywanttoadd:/application/php5.6.24/lib/phptoyourphp.iniinclude_path /tools/php-5.6.24/build/shtoolinstall-cext/phar/phar.phar/application/php5.6.24/bin ln-s-fphar.phar/application/php5.6.24/bin/phar InstallingPDOheaders:/application/php5.6.24/include/php/ext/pdo/ [root@centos02php-5.6.24]#ln-s/application/php5.6.24//application/php [root@centos02php-5.6.24]#cpphp.ini-production/application/php/lib/php.ini [root@centos02php-5.6.24]#cd/application/php/etc/ [root@centos02etc]#cpphp-fpm.conf.defaultphp-fpm.conf [root@centos02etc]#catphp-fpm.conf [global] [www] user=nginx group=nginx listen=127.0.0.1:9000 pm=dynamic pm.max_children=5 pm.start_servers=2 pm.min_spare_servers=1 pm.max_spare_servers=3 [root@centos02etc]#/application/php/sbin/php-fpm nginx配置如下 [root@centos02etc]#cat/application/nginx/conf/nginx.conf worker_processes2; events{ worker_connections1024; } http{ log_formatmain'$remote_addr-$remote_user[$time_local]"$request"' '$status$body_bytes_sent"$http_referer"' '"$http_user_agent""$http_x_forwarded_for"'; includemime.types; default_typeapplication/octet-stream; sendfileon; keepalive_timeout65; server{ listen80; server_namewww.martin.commartin.com; location/{ roothtml/www; indexindex.phpindex.htmlindex.htm; } location~.*\.(php|php5)?${ roothtml/www; fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; includefastcgi.conf; } access_loglogs/access_www.logmain; } server{ listen80; server_namebbs.martin.com; location/{ roothtml/bbs; indexindex.phpindex.htmlindex.htm; } location~.*\.(php|php5)?${ fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; includefastcgi.conf; } access_loglogs/access_bbs.logmain; } ###status server{ listen80; server_namestatus.martin.org; location/{ stub_statuson; access_logoff; } } } 浏览器访问测试 (www.martin.com---172.16.80.117) 至此整个LNMP环境准备完成,zabbix(在LNMP环境下)选择源码编译安装 curl 7.19.7 系统默认版本,升级该软件版本,否则后面邮件功能会有问题 [root@centos02application]#rpm-Uvhhttp://www.city-fan.org/ftp/contrib/yum-repo/rhel6/x86_64/city-fan.org-release-1-13.rhel6.noarch.rpm Retrievinghttp://www.city-fan.org/ftp/contrib/yum-repo/rhel6/x86_64/city-fan.org-release-1-13.rhel6.noarch.rpm warning:/var/tmp/rpm-tmp.jSwm5A:HeaderV3DSA/SHA1Signature,keyIDb56a8bac:NOKEY Preparing...###########################################[100%] 1:city-fan.org-release###########################################[100%] [root@centos02application]#yuminstalllibcurl-y [root@centos02application]#curl-V再次查看版本 curl7.50.1(x86_64-redhat-linux-gnu)libcurl/7.50.1OpenSSL/1.0.1ezlib/1.2.3c-ares/1.11.0libidn/1.18libssh2/1.7.0nghttp2/1.6.0 Protocols:dictfileftpftpsgopherhttphttpsimapimapsldapldapspop3pop3srtspscpsftpsmbsmbssmtpsmtpstelnettftp Features:AsynchDNSIDNIPv6LargefileGSS-APIKerberosSPNEGONTLMNTLM_WBSSLlibzHTTP2UnixSocketsMetalink 安装zabbix依赖包 [root@centos02zabbix-3.0.4]#yum-yinstallmysql-devellibxml2-develnet-snmp-devellibcurl-devel [root@centos02tools]#wgethttp://ncu.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.4/zabbix-3.0.4.tar.gz [root@centos02tools]#tarxfzabbix-3.0.4.tar.gz [root@centos02tools]#cdzabbix-3.0.4 [root@centos02zabbix-3.0.4]#./configure--prefix=/application/zabbix-server--enable-server--with-mysql--with-net-snmp--with-libcurl--with-libxml2--enable-agent--enable-proxy Enableserver:yes Serverdetails: Withdatabase:MySQL WEBMonitoring:cURL NativeJabber:no SNMP:yes IPMI:no SSH:no TLS:no ODBC:no Linkerflags:-L/usr/lib64/mysql-L/usr/lib64-rdynamic Libraries:-lmysqlclient-lxml2-lnetsnmp-lcurl-lm-ldl-lrt-lresolv Enableproxy:yes Proxydetails: Withdatabase:MySQL WEBMonitoring:cURL SNMP:yes IPMI:no SSH:no TLS:no ODBC:no Linkerflags:-L/usr/lib64/mysql-L/usr/lib64-rdynamic Libraries:-lmysqlclient-lxml2-lnetsnmp-lcurl-lm-ldl-lrt-lresolv Enableagent:yes Agentdetails: TLS:no Linkerflags:-rdynamic Libraries:-lcurl-lm-ldl-lrt-lresolv EnableJavagateway:no LDAPsupport:no IPv6support:no *********************************************************** *Nowrun'makeinstall'* ** *ThankyouforusingZabbix!* *<http://www.zabbix.com>* *********************************************************** [root@centos02 zabbix-3.0.4]# make install 由于zabbix启动脚本路径默认指向的是/usr/local/sbin路径,因此,需要提前建立软链接 [root@centos02zabbix-3.0.4]#ln-s/application/zabbix-server/sbin/*/usr/local/sbin/ [root@centos02zabbix-3.0.4]#ln-s/application/zabbix-server/bin/*/usr/local/bin/ 生成zabbix的web文件 [root@centos02zabbix-3.0.4]#mkdir/application/nginx/html/zabbix [root@centos02zabbix-3.0.4]#cp-a/tools/zabbix-3.0.4/frontends/php/*/application/nginx/html/zabbix/ 手动创建zabbix数据库及授权 [root@centos02zabbix-3.0.4]#mysql-uroot-p123456 WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis4 Serverversion:5.5.49-logMySQLCommunityServer(GPL) Copyright(c)2000,2013,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>createdatabasezabbixdefaultcharsetutf8; QueryOK,1rowaffected(0.16sec) mysql>grantallonzabbix.*tozabbix@'localhost'identifiedby'zabbix'; QueryOK,0rowsaffected(0.16sec) mysql>flushprivileges; QueryOK,0rowsaffected(0.19sec) 导入zabbix数据库文件 [root@centos02mysql]#pwd /tools/zabbix-3.0.4/database/mysql [root@centos02mysql]#mysql-uzabbix-pzabbixzabbix<schema.sql [root@centos02mysql]#mysql-uzabbix-pzabbixzabbix<p_w_picpaths.sql [root@centos02mysql]#mysql-uzabbix-pzabbixzabbix<data.sql 配置zabbixserver端 修改zabbix配置文件,配置zabbix_server cd/usr/local/zabbix/etc vi/usr/local/zabbix/etc/zabbix_server.conf DBName=zabbix#数据库名称 DBUser=zabbix#数据库用户名 DBPassword=zabbix#数据库密码 ListenIP=localhost#数据库ip地址 DBSocket=/tmp/mysql.sock#这里填写mysql实际的socket位置查看/etc/my.cnf即可 AlertScriptsPath=/application/zabbix-server/share/zabbix/alertscripts#zabbix运行脚本存放目录 修改php.ini文件/application/php/lib/php.ini post_max_size=16M max_execution_time=300 memory_limit=128M max_input_time=300 date.timezone=Asia/Shanghai always_populate_raw_post_data=-1 extension=php_gettext.dll 修改nginx配置文件如下 [root@centos02mysql]#cat/application/nginx/conf/nginx.conf worker_processes2; events{ worker_connections1024; } http{ log_formatmain'$remote_addr-$remote_user[$time_local]"$request"' '$status$body_bytes_sent"$http_referer"' '"$http_user_agent""$http_x_forwarded_for"'; includemime.types; default_typeapplication/octet-stream; sendfileon; keepalive_timeout65; server{ listen80; server_namewww.martin.commartin.com; location/{ roothtml/zabbix; indexindex.phpindex.htmlindex.htm; } location~.*\.(php|php5)?${ roothtml/zabbix; fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; includefastcgi.conf; } access_loglogs/access_zabbix.logmain; } server{ listen80; server_namebbs.martin.com; location/{ roothtml/bbs; indexindex.phpindex.htmlindex.htm; } location~.*\.(php|php5)?${ fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; includefastcgi.conf; } access_loglogs/access_bbs.logmain; } ###status server{ listen80; server_namestatus.martin.org; location/{ stub_statuson; access_logoff; } } } [root@centos02mysql]#/application/nginx/sbin/nginx-sreload [root@centos02mysql]#useradd-s/sbin/nologin-Mzabbix [root@centos02mysql]#/etc/init.d/zabbix_serverstart Startingzabbix_server:[OK] [root@centos02mysql]#/application/php/sbin/php-fpm [root@centos02init.d]#/application/zabbix-server/sbin/zabbix_server-c/application/zabbix-server/etc/zabbix_server.conf 浏览器访问http://www.martin.com/ 用户名/密码 默认是 Admin/zabbix 再来看下中文界面 安装agent [root@centos02tools]#wgethttp://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm [root@centos02tools]#rpm-ivhzabbix-release-3.0-1.el6.noarch.rpm Preparing...###########################################[100%] 1:zabbix-release###########################################[100%] [root@centos02tools]#yum-yinstallzabbix-agent [root@centos02tools]#/etc/init.d/zabbix-agentstart启动agent StartingZabbixagent:[OK] 按照图示步骤启用主机监控即可 这次我们简单介绍到这里,下篇我们正式开始介绍zabbix监控

优秀的个人博客,低调大师

使用hadoop平台进行小型网站日志分析

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq1010885678/article/details/44688325 0.上传日志文件到linux中,通过flume将文件收集到hdfs中。 执行命令/home/cloud/flume/bin/flume-ng agent -n a4 -c conf -f /home/cloud/flume/conf/a4.conf -Dflume.root.logger=DEBUG,console 1.建立hive表 create external table bbslog (ip string,logtime string,url string) partitioned by (logdate string) row format delimited fields terminated by '\t' location '/cleaned'; 2.创建shell脚本 touch daily.sh 添加执行权限 chmod +x daily.sh daily.sh: CURRENT=`date +%Y%m%d` #对数据进行清理,保存到cleaned文件夹,按照当前日期进行保存 /home/cloud/hadoop/bin/hadoop jar /home/cloud/cleaner.jar /flume/$CURRENT /cleaned/$CURRENT #修改hive表,添加当前日期的分区 /home/cloud/hive/bin/hive -e "alter table bbslog add partition (logdate=$CURRENT) location 'cleaned/$CURRENT'" #使用hive进行分析,根据业务需求而定 #统计pv并计入每日的pv表 /home/cloud/hive/bin/hive -e "create table pv_$CURRENT row format delimited fields terminated by '\t' as select count(*) from bbslog where logdate=$CURRENT;" #统计点击次数过20的潜在用户 /home/cloud/hive/bin/hive -e "create table vip _$CURRENT row format delimited fields terminated by '\t' as select $CURRENT,ip,count(*) as hits from bbslog where logdate=$CURRENT group by ip having hits > 20 order by hits desc" #查询uv /home/cloud/hive/bin/hive -e "create table uv_$CURRENT row format delimited fields terminated by '\t' as select count(distinct ip) from bbslog where logdate=$CURRENT" #查询每天的注册人数 /home/cloud/hive/bin/hive -e "create table reg_$CURRENT row format delimited fields terminated by '\t' as select count(*) from bbslog where logdate=$CURRENT AND instr(url,'member.php?mod=register')>0" #将hive表中的数据导入mysql /home/cloud/sqoop/bin/sqoop export --connect jdbc:mysql://cloud3:3306/jchubby --username root --password JChubby123 --export-dir "/user/hive/warehouse/vip_$CURRENT" --table vip --fields-terminated-by '\t'

优秀的个人博客,低调大师

20、 Python快速开发分布式搜索引擎Scrapy精讲—编写spiders爬虫文件循环抓取内容—meta属性返回指定值给回调函数—Scr...

编写spiders爬虫文件循环抓取内容 Request()方法,将指定的url地址添加到下载器下载页面,两个必须参数, 参数: url='url' callback=页面处理函数 使用时需要yield Request() parse.urljoin()方法,是urllib库下的方法,是自动url拼接,如果第二个参数的url地址是相对路径会自动与第一个参数拼接 #-*-coding:utf-8-*- importscrapy fromscrapy.httpimportRequest#导入url返回给下载器的方法 fromurllibimportparse#导入urllib库里的parse模块 classPachSpider(scrapy.Spider): name='pach' allowed_domains=['blog.jobbole.com']#起始域名 start_urls=['http://blog.jobbole.com/all-posts/']#起始url defparse(self,response): """ 获取列表页的文章url地址,交给下载器 """ #获取当前页文章url lb_url=response.xpath('//a[@class="archive-title"]/@href').extract()#获取文章列表url foriinlb_url: #print(parse.urljoin(response.url,i))#urllib库里的parse模块的urljoin()方法,是自动url拼接,如果第二个参数的url地址是相对路径会自动与第一个参数拼接 yieldRequest(url=parse.urljoin(response.url,i),callback=self.parse_wzhang)#将循环到的文章url添加给下载器,下载后交给parse_wzhang回调函数 #获取下一页列表url,交给下载器,返回给parse函数循环 x_lb_url=response.xpath('//a[@class="nextpage-numbers"]/@href').extract()#获取下一页文章列表url ifx_lb_url: yieldRequest(url=parse.urljoin(response.url,x_lb_url[0]),callback=self.parse)#获取到下一页url返回给下载器,回调给parse函数循环进行 defparse_wzhang(self,response): title=response.xpath('//div[@class="entry-header"]/h1/text()').extract()#获取文章标题 print(title) Request()函数在返回url时,同时可以通过meta属性返回一个自定义字典给回调函数 #-*-coding:utf-8-*- importscrapy fromscrapy.httpimportRequest#导入url返回给下载器的方法 fromurllibimportparse#导入urllib库里的parse模块 fromadc.itemsimportAdcItem#导入items数据接收模块的接收类 classPachSpider(scrapy.Spider): name='pach' allowed_domains=['blog.jobbole.com']#起始域名 start_urls=['http://blog.jobbole.com/all-posts/']#起始url defparse(self,response): """ 获取列表页的文章url地址,交给下载器 """ #获取当前页文章url lb=response.css('div.post.floated-thumb')#获取文章列表区块,css选择器 #print(lb) foriinlb: lb_url=i.css('.archive-title::attr(href)').extract_first('')#获取区块里文章url #print(lb_url) lb_img=i.css('.post-thumbimg::attr(src)').extract_first('')#获取区块里文章缩略图 #print(lb_img) yieldRequest(url=parse.urljoin(response.url,lb_url),meta={'lb_img':parse.urljoin(response.url,lb_img)},callback=self.parse_wzhang)#将循环到的文章url添加给下载器,下载后交给parse_wzhang回调函数 #获取下一页列表url,交给下载器,返回给parse函数循环 x_lb_url=response.css('.next.page-numbers::attr(href)').extract_first('')#获取下一页文章列表url ifx_lb_url: yieldRequest(url=parse.urljoin(response.url,x_lb_url),callback=self.parse)#获取到下一页url返回给下载器,回调给parse函数循环进行 defparse_wzhang(self,response): title=response.css('.entry-headerh1::text').extract()#获取文章标题 #print(title) tp_img=response.meta.get('lb_img','')#接收meta传过来的值,用get获取防止出错 #print(tp_img) shjjsh=AdcItem()#实例化数据接收类 shjjsh['title']=title#将数据传输给items接收模块的指定类 shjjsh['img']=tp_img yieldshjjsh#将接收对象返回给pipelines.py处理模块 * Scrapy内置图片下载器使用 Scrapy给我们内置了一个图片下载器在crapy.pipelines.images.ImagesPipeline,专门用于将爬虫抓取到图片url后将图片下载到本地 第一步、爬虫抓取图片URL地址后,填充到items.py文件的容器函数 爬虫文件 #-*-coding:utf-8-*- importscrapy fromscrapy.httpimportRequest#导入url返回给下载器的方法 fromurllibimportparse#导入urllib库里的parse模块 fromadc.itemsimportAdcItem#导入items数据接收模块的接收类 classPachSpider(scrapy.Spider): name='pach' allowed_domains=['blog.jobbole.com']#起始域名 start_urls=['http://blog.jobbole.com/all-posts/']#起始url defparse(self,response): """ 获取列表页的文章url地址,交给下载器 """ #获取当前页文章url lb=response.css('div.post.floated-thumb')#获取文章列表区块,css选择器 #print(lb) foriinlb: lb_url=i.css('.archive-title::attr(href)').extract_first('')#获取区块里文章url #print(lb_url) lb_img=i.css('.post-thumbimg::attr(src)').extract_first('')#获取区块里文章缩略图 #print(lb_img) yieldRequest(url=parse.urljoin(response.url,lb_url),meta={'lb_img':parse.urljoin(response.url,lb_img)},callback=self.parse_wzhang)#将循环到的文章url添加给下载器,下载后交给parse_wzhang回调函数 #获取下一页列表url,交给下载器,返回给parse函数循环 x_lb_url=response.css('.next.page-numbers::attr(href)').extract_first('')#获取下一页文章列表url ifx_lb_url: yieldRequest(url=parse.urljoin(response.url,x_lb_url),callback=self.parse)#获取到下一页url返回给下载器,回调给parse函数循环进行 defparse_wzhang(self,response): title=response.css('.entry-headerh1::text').extract()#获取文章标题 #print(title) tp_img=response.meta.get('lb_img','')#接收meta传过来的值,用get获取防止出错 #print(tp_img) shjjsh=AdcItem()#实例化数据接收类 shjjsh['title']=title#将数据传输给items接收模块的指定类 shjjsh['img']=[tp_img] yieldshjjsh#将接收对象返回给pipelines.py处理模块 第二步、设置items.py文件的容器函数,接收爬虫获取到的数据填充 #-*-coding:utf-8-*- #Defineherethemodelsforyourscrapeditems # #Seedocumentationin: #http://doc.scrapy.org/en/latest/topics/items.html importscrapy #items.py,文件是专门用于,接收爬虫获取到的数据信息的,就相当于是容器文件 classAdcItem(scrapy.Item):#设置爬虫获取到的信息容器类 title=scrapy.Field()#接收爬虫获取到的title信息 img=scrapy.Field()#接收缩略图 img_tplj=scrapy.Field()#图片保存路径 第三步、在pipelines.py使用crapy内置的图片下载器 1、首先引入内置图片下载器 2、自定义一个图片下载内,继承crapy内置的ImagesPipeline图片下载器类 3、使用ImagesPipeline类里的item_completed()方法获取到图片下载后的保存路径 4、在settings.py设置文件里,注册自定义图片下载器类,和设置图片保存路径 #-*-coding:utf-8-*- #Defineyouritempipelineshere # #Don'tforgettoaddyourpipelinetotheITEM_PIPELINESsetting #See:http://doc.scrapy.org/en/latest/topics/item-pipeline.html fromscrapy.pipelines.imagesimportImagesPipeline#导入图片下载器模块 classAdcPipeline(object):#定义数据处理类,必须继承object defprocess_item(self,item,spider):#process_item(item)为数据处理函数,接收一个item,item里就是爬虫最后yielditem来的数据对象 print('文章标题是:'+item['title'][0]) print('文章缩略图url是:'+item['img'][0]) print('文章缩略图保存路径是:'+item['img_tplj'])#接收图片下载器填充的,图片下载后的路径 returnitem classimgPipeline(ImagesPipeline):#自定义一个图片下载内,继承crapy内置的ImagesPipeline图片下载器类 defitem_completed(self,results,item,info):#使用ImagesPipeline类里的item_completed()方法获取到图片下载后的保存路径 forok,valueinresults: img_lj=value['path']#接收图片保存路径 #print(ok) item['img_tplj']=img_lj#将图片保存路径填充到items.py里的字段里 returnitem#将item给items.py文件的容器函数 #注意:自定义图片下载器设置好后,需要在 在settings.py设置文件里,注册自定义图片下载器类,和设置图片保存路径 IMAGES_URLS_FIELD设置要下载图片的url地址,一般设置的items.py里接收的字段IMAGES_STORE设置图片保存路径 #Configureitempipelines #Seehttp://scrapy.readthedocs.org/en/latest/topics/item-pipeline.html ITEM_PIPELINES={ 'adc.pipelines.AdcPipeline':300,#注册adc.pipelines.AdcPipeline类,后面一个数字参数表示执行等级, 'adc.pipelines.imgPipeline':1,#注册自定义图片下载器,数值越小,越优先执行 } IMAGES_URLS_FIELD='img'#设置要下载图片的url字段,就是图片在items.py里的字段里 lujin=os.path.abspath(os.path.dirname(__file__)) IMAGES_STORE=os.path.join(lujin,'img')#设置图片保存路径 【转载自:http://www.lqkweb.com】

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册