From 3b405f129707b7b58f02482979b4121802ff798a Mon Sep 17 00:00:00 2001 From: hihell Date: Thu, 4 Nov 2021 20:50:29 +0800 Subject: [PATCH] =?UTF-8?q?49&50=E6=A1=88=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NO49/csdn/__init__.py | 0 NO49/csdn/__pycache__/__init__.cpython-37.pyc | Bin 0 -> 145 bytes NO49/csdn/__pycache__/settings.cpython-37.pyc | Bin 0 -> 273 bytes NO49/csdn/items.py | 12 ++ NO49/csdn/middlewares.py | 105 ++++++++++++++++ NO49/csdn/pipelines.py | 13 ++ NO49/csdn/settings.py | 89 +++++++++++++ NO49/csdn/spiders/__init__.py | 4 + .../__pycache__/__init__.cpython-37.pyc | Bin 0 -> 153 bytes .../csdn/spiders/__pycache__/c.cpython-37.pyc | Bin 0 -> 761 bytes NO49/csdn/spiders/c.py | 15 +++ NO49/scrapy.cfg | 11 ++ NO50/mid_test/__init__.py | 0 .../__pycache__/__init__.cpython-37.pyc | Bin 0 -> 149 bytes .../__pycache__/middlewares.cpython-37.pyc | Bin 0 -> 3244 bytes .../__pycache__/settings.cpython-37.pyc | Bin 0 -> 342 bytes NO50/mid_test/items.py | 12 ++ NO50/mid_test/middlewares.py | 117 ++++++++++++++++++ NO50/mid_test/pipelines.py | 13 ++ NO50/mid_test/settings.py | 90 ++++++++++++++ NO50/mid_test/spiders/__init__.py | 4 + .../__pycache__/__init__.cpython-37.pyc | Bin 0 -> 157 bytes .../spiders/__pycache__/hbin.cpython-37.pyc | Bin 0 -> 576 bytes NO50/mid_test/spiders/hbin.py | 10 ++ NO50/scrapy.cfg | 11 ++ README.md | 2 + 26 files changed, 508 insertions(+) create mode 100644 NO49/csdn/__init__.py create mode 100644 NO49/csdn/__pycache__/__init__.cpython-37.pyc create mode 100644 NO49/csdn/__pycache__/settings.cpython-37.pyc create mode 100644 NO49/csdn/items.py create mode 100644 NO49/csdn/middlewares.py create mode 100644 NO49/csdn/pipelines.py create mode 100644 NO49/csdn/settings.py create mode 100644 NO49/csdn/spiders/__init__.py create mode 100644 NO49/csdn/spiders/__pycache__/__init__.cpython-37.pyc create mode 100644 NO49/csdn/spiders/__pycache__/c.cpython-37.pyc create mode 100644 NO49/csdn/spiders/c.py create mode 100644 NO49/scrapy.cfg create mode 100644 NO50/mid_test/__init__.py create mode 100644 NO50/mid_test/__pycache__/__init__.cpython-37.pyc create mode 100644 NO50/mid_test/__pycache__/middlewares.cpython-37.pyc create mode 100644 NO50/mid_test/__pycache__/settings.cpython-37.pyc create mode 100644 NO50/mid_test/items.py create mode 100644 NO50/mid_test/middlewares.py create mode 100644 NO50/mid_test/pipelines.py create mode 100644 NO50/mid_test/settings.py create mode 100644 NO50/mid_test/spiders/__init__.py create mode 100644 NO50/mid_test/spiders/__pycache__/__init__.cpython-37.pyc create mode 100644 NO50/mid_test/spiders/__pycache__/hbin.cpython-37.pyc create mode 100644 NO50/mid_test/spiders/hbin.py create mode 100644 NO50/scrapy.cfg diff --git a/NO49/csdn/__init__.py b/NO49/csdn/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/NO49/csdn/__pycache__/__init__.cpython-37.pyc b/NO49/csdn/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..47e3e977e94e290bdfb595c76609db6f858368c6 GIT binary patch literal 145 zcmZ?b<>g`kg7A=tL=gQLM8E(ekl_Ht#VkM~g&~+hlhJP_LlHm;nGcWF{W~ literal 0 HcmV?d00001 diff --git a/NO49/csdn/__pycache__/settings.cpython-37.pyc b/NO49/csdn/__pycache__/settings.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..07cb0a3c217ae06a271fb15f57b1255823f7b347 GIT binary patch literal 273 zcmZ?b<>g`k0(tGS#E;wz439w^7+?f49Dul33P_|dL@}f=rZYw{rZ7e^r7%S?r!Ysc zq_6}tXtGAJBp0XTRq=pGz2bt*l+>bPw_EJtjzNB&e(rvnthYFv{6pgX9DQAH@dXEX zy0`|#`}(_t`nU$)67X{kM-jTk7vv9A9UKx767TQi8hMM;$KO5P$2H8=XC*@sJJ2a$ z;;T83V?geTDNZdZ k$;?YH)+?yI#bJ}1pHiBWY6tRsF$a)fVPa!sVP|m#0NTDx(EtDd literal 0 HcmV?d00001 diff --git a/NO49/csdn/items.py b/NO49/csdn/items.py new file mode 100644 index 0000000..ffc1ebb --- /dev/null +++ b/NO49/csdn/items.py @@ -0,0 +1,12 @@ +# Define here the models for your scraped items +# +# See documentation in: +# https://docs.scrapy.org/en/latest/topics/items.html + +import scrapy + + +class CsdnItem(scrapy.Item): + # define the fields for your item here like: + # name = scrapy.Field() + pass diff --git a/NO49/csdn/middlewares.py b/NO49/csdn/middlewares.py new file mode 100644 index 0000000..d41669b --- /dev/null +++ b/NO49/csdn/middlewares.py @@ -0,0 +1,105 @@ +# Define here the models for your spider middleware +# +# See documentation in: +# https://docs.scrapy.org/en/latest/topics/spider-middleware.html + +from scrapy import signals + +# useful for handling different item types with a single interface +from itemadapter import is_item, ItemAdapter + + +class CsdnSpiderMiddleware: + # Not all methods need to be defined. If a method is not defined, + # scrapy acts as if the spider middleware does not modify the + # passed objects. + + @classmethod + def from_crawler(cls, crawler): + # This method is used by Scrapy to create your spiders. + s = cls() + crawler.signals.connect(s.spider_opened, signal=signals.spider_opened) + return s + + def process_spider_input(self, response, spider): + # Called for each response that goes through the spider + # middleware and into the spider. + + # Should return None or raise an exception. + return None + + def process_spider_output(self, response, result, spider): + # Called with the results returned from the Spider, after + # it has processed the response. + + # Must return an iterable of Request, or item objects. + for i in result: + yield i + + def process_spider_exception(self, response, exception, spider): + # Called when a spider or process_spider_input() method + # (from other spider middleware) raises an exception. + + # Should return either None or an iterable of Request or item objects. + pass + + def process_start_requests(self, start_requests, spider): + # Called with the start requests of the spider, and works + # similarly to the process_spider_output() method, except + # that it doesn’t have a response associated. + + # Must return only requests (not items). + for r in start_requests: + yield r + + def spider_opened(self, spider): + spider.logger.info('Spider opened: %s' % spider.name) + + +class CsdnDownloaderMiddleware: + # Not all methods need to be defined. If a method is not defined, + # scrapy acts as if the downloader middleware does not modify the + # passed objects. + + @classmethod + def from_crawler(cls, crawler): + # This method is used by Scrapy to create your spiders. + s = cls() + crawler.signals.connect(s.spider_opened, signal=signals.spider_opened) + return s + + def process_request(self, request, spider): + # Called for each request that goes through the downloader + # middleware. + + # Must either: + # - return None: continue processing this request + # - or return a Response object + # - or return a Request object + # - or raise IgnoreRequest: process_exception() methods of + # installed downloader middleware will be called + return None + + def process_response(self, request, response, spider): + # Called with the response returned from the downloader. + + # Must either; + # - return a Response object + # - return a Request object + # - or raise IgnoreRequest + return response + + def process_exception(self, request, exception, spider): + # Called when a download handler or a process_request() + # (from other downloader middleware) raises an exception. + + # Must either: + # - return None: continue processing this exception + # - return a Response object: stops process_exception() chain + # - return a Request object: stops process_exception() chain + pass + + def spider_opened(self, spider): + spider.logger.info('Spider opened: %s' % spider.name) + + diff --git a/NO49/csdn/pipelines.py b/NO49/csdn/pipelines.py new file mode 100644 index 0000000..797e40e --- /dev/null +++ b/NO49/csdn/pipelines.py @@ -0,0 +1,13 @@ +# Define your item pipelines here +# +# Don't forget to add your pipeline to the ITEM_PIPELINES setting +# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html + + +# useful for handling different item types with a single interface +from itemadapter import ItemAdapter + + +class CsdnPipeline: + def process_item(self, item, spider): + return item diff --git a/NO49/csdn/settings.py b/NO49/csdn/settings.py new file mode 100644 index 0000000..f9e335e --- /dev/null +++ b/NO49/csdn/settings.py @@ -0,0 +1,89 @@ +# Scrapy settings for csdn project +# +# For simplicity, this file contains only settings considered important or +# commonly used. You can find more settings consulting the documentation: +# +# https://docs.scrapy.org/en/latest/topics/settings.html +# https://docs.scrapy.org/en/latest/topics/downloader-middleware.html +# https://docs.scrapy.org/en/latest/topics/spider-middleware.html + +BOT_NAME = 'csdn' + +SPIDER_MODULES = ['csdn.spiders'] +NEWSPIDER_MODULE = 'csdn.spiders' + + +# Crawl responsibly by identifying yourself (and your website) on the user-agent +#USER_AGENT = 'csdn (+http://www.yourdomain.com)' + +# Obey robots.txt rules +ROBOTSTXT_OBEY = False + +# Configure maximum concurrent requests performed by Scrapy (default: 16) +#CONCURRENT_REQUESTS = 32 + +# Configure a delay for requests for the same website (default: 0) +# See https://docs.scrapy.org/en/latest/topics/settings.html#download-delay +# See also autothrottle settings and docs +#DOWNLOAD_DELAY = 3 +# The download delay setting will honor only one of: +#CONCURRENT_REQUESTS_PER_DOMAIN = 16 +#CONCURRENT_REQUESTS_PER_IP = 16 + +# Disable cookies (enabled by default) +#COOKIES_ENABLED = False + +# Disable Telnet Console (enabled by default) +#TELNETCONSOLE_ENABLED = False + +# Override the default request headers: +#DEFAULT_REQUEST_HEADERS = { +# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', +# 'Accept-Language': 'en', +#} + +# Enable or disable spider middlewares +# See https://docs.scrapy.org/en/latest/topics/spider-middleware.html +#SPIDER_MIDDLEWARES = { +# 'csdn.middlewares.CsdnSpiderMiddleware': 543, +#} + +# Enable or disable downloader middlewares +# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html +#DOWNLOADER_MIDDLEWARES = { +# 'csdn.middlewares.CsdnDownloaderMiddleware': 543, +#} + +# Enable or disable extensions +# See https://docs.scrapy.org/en/latest/topics/extensions.html +#EXTENSIONS = { +# 'scrapy.extensions.telnet.TelnetConsole': None, +#} + +# Configure item pipelines +# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html +#ITEM_PIPELINES = { +# 'csdn.pipelines.CsdnPipeline': 300, +#} + +# Enable and configure the AutoThrottle extension (disabled by default) +# See https://docs.scrapy.org/en/latest/topics/autothrottle.html +#AUTOTHROTTLE_ENABLED = True +# The initial download delay +#AUTOTHROTTLE_START_DELAY = 5 +# The maximum download delay to be set in case of high latencies +#AUTOTHROTTLE_MAX_DELAY = 60 +# The average number of requests Scrapy should be sending in parallel to +# each remote server +#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0 +# Enable showing throttling stats for every response received: +#AUTOTHROTTLE_DEBUG = False + +# Enable and configure HTTP caching (disabled by default) +# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings +#HTTPCACHE_ENABLED = True +#HTTPCACHE_EXPIRATION_SECS = 0 +#HTTPCACHE_DIR = 'httpcache' +#HTTPCACHE_IGNORE_HTTP_CODES = [] +#HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage' +LOG_LEVEL = 'WARNING' \ No newline at end of file diff --git a/NO49/csdn/spiders/__init__.py b/NO49/csdn/spiders/__init__.py new file mode 100644 index 0000000..ebd689a --- /dev/null +++ b/NO49/csdn/spiders/__init__.py @@ -0,0 +1,4 @@ +# This package will contain the spiders of your Scrapy project +# +# Please refer to the documentation for information on how to create and manage +# your spiders. diff --git a/NO49/csdn/spiders/__pycache__/__init__.cpython-37.pyc b/NO49/csdn/spiders/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6e59b106278422b8a5a0a868a4e93e19d765db03 GIT binary patch literal 153 zcmZ?b<>g`kg7A=t#DzfmF^B^Lj6jA15Erumi4=xl22Do4l?+87VFdBj9>{gIiYcfp z$;i(OD9X=DO)iOf-m&Jz%+-cQ22b{NKby1W>6{HQCYCYD#VL6)#RZuusYS&x@$s2? bnI-Y@dIgoYIBatBQ%ZAE?LcOK24V&P?lLMK literal 0 HcmV?d00001 diff --git a/NO49/csdn/spiders/__pycache__/c.cpython-37.pyc b/NO49/csdn/spiders/__pycache__/c.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1911ee1c875ac5ce1e947940a58e5c921fdafb53 GIT binary patch literal 761 zcmYjPOK%e~5caHhH>)%uJ#gWUkaEcugm_d4Ra6L05o&I$l~&8zj&z@C*1Md*%HDxHGd!q>kio#va?>%x6F9cH0c??!oKyBQW-zCL41x*u!D& zAP6Qvv535*Aa^1MDCUaiZsY=c!h|clcT9Ma&AekC`2t3)@BhWKY}ki77)d2FTWX9u zPi?Laq^Zin$c%Pu%)wv}hq;a*Sp=LIxihT6JrGR857{HDrq* zGolz2(k^aHtgXy$7(Q3!c(7Rxby~a()zsK9E7d$NGGZj->#>jC>>yaSWHS(O4Ld%8 zBe2dA1V4c@F5GiCbI;k4W4)zw45S2B;te%Q$gn>?*NR%!>lPQSFtk&vWZ&1sQ@4#x zwM}rF(NsX~y{%F^srgvi+N<=muzg;;MyeOOMR~5J{mk?gjQ`z3c)S}|hjvmH&vZFM zS>xaDFaCV`a`V>Ck8dA-onHJr{TkoCA5+`0Y1A=sHmDBq@>CnSg;y9Kfx)(O6&BsK zgo7qKL{WnzDbidfN!?D8ycBaqaVJS$%~Q3`xa8|zs#N(#ibRxoIxUP2@LIi1K;>S7 z9!=?25woFf0l46U?=-8(>YGfbSY>bJ2Pi=EXI3I@tyk$~S33Humv4?=B5HVvtqvZn PYJW&C({vm_2Ri&e)&0U+ literal 0 HcmV?d00001 diff --git a/NO49/csdn/spiders/c.py b/NO49/csdn/spiders/c.py new file mode 100644 index 0000000..c80676b --- /dev/null +++ b/NO49/csdn/spiders/c.py @@ -0,0 +1,15 @@ +import scrapy +from scrapy.selector import Selector +from scrapy.http import HtmlResponse + + +class CSpider(scrapy.Spider): + name = 'c' + allowed_domains = ['csdn.net'] + start_urls = ['https://blog.csdn.net/rank/list/column'] + + def parse(self, response): + response = HtmlResponse(url=self.start_urls[0]) + + ret = Selector(response=response).xpath("//title").get() + print(ret) diff --git a/NO49/scrapy.cfg b/NO49/scrapy.cfg new file mode 100644 index 0000000..1e233dd --- /dev/null +++ b/NO49/scrapy.cfg @@ -0,0 +1,11 @@ +# Automatically created by: scrapy startproject +# +# For more information about the [deploy] section see: +# https://scrapyd.readthedocs.io/en/latest/deploy.html + +[settings] +default = csdn.settings + +[deploy] +#url = http://localhost:6800/ +project = csdn diff --git a/NO50/mid_test/__init__.py b/NO50/mid_test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/NO50/mid_test/__pycache__/__init__.cpython-37.pyc b/NO50/mid_test/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..01af5c33c2a9711c85b0b92ef1817b8c8ff832af GIT binary patch literal 149 zcmZ?b<>g`kg7A=tL=gQLM8E(ekl_Ht#VkM~g&~+hlhJP_LlHFDN_r`^XcSd zl|cLLk8i!_2MBqFlU_4mun1k=2EhoU0cq1Fr8w3Ct*tlpw$U^wxk;GLj7NkSyIQjZ zvl265X2Q&bS(#Zdvv_$|Z(6LfOq}Y!ppiHUpOq>MB*t~1KCM`V{ajSNMzl%3x+vy+=;R$h8hDRkunbOs|}DQzgMV1*%hu$Eea%Qy-p z2lJJgYB>{=uqizpi>Sq=baOBGVZ4HfAy|D z(!Uw@bV??kNL;};w;(=c?qV?v|7Zb!;PZOnV-tK_e4;S)@!2A=KC^(ZStWvFPl`RW;MXg}^6itWGB6N8P#H-OPIJK6Z$nC!oZHGbR zy*`Q+NM<>|iZYCq+3=!*W4zDA1PW#So(s@vi_rVI@XS6KUx^P@c%)iMot>6rGdF`=DR3-bhRb_jG4GzFdGR7t}oJN7jcojz=|c zarC3Y)EtRwx~IG#rqu$LRZ#D~u!^0pixtEPMEfR+w?Mpz5Y`I7wBzjebB9QwBCy^N zc-aUW#k(j}-k-$LDHNwsj7|CXVD$=gi5a0%zGhXds=)UH36HV22wkF8y@b!Is-~XT zR0bEZApm zeZI1E`>Y-K_qlzOx9&%def=I3KYZq6&{v;ZxNxaHKW8s{Yo74)U07`1<48y{txBFS zzUDz000g2+1C=SG2p%0DK+gz-TGZ5lG6lYA zI29=Ppw5hUvTAn%D|j!f-311NKxFEUQE``=(Os-()$TrmE)GhqPqGW}Dw4d!;I8Qh K^{JVung0R2jpIrH literal 0 HcmV?d00001 diff --git a/NO50/mid_test/__pycache__/settings.cpython-37.pyc b/NO50/mid_test/__pycache__/settings.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9bfddf19eeac2b212cdf06c3f4ca9f75b4d3bd64 GIT binary patch literal 342 zcmZ?b<>g`kf`~(9iGn-~439w^7+?Z29Dul34oIXhL@}f=rZYw{rZ7e^r7%S?r!c3m zWHLsvq_74vXtG6dBV{lmA5!- Za`RJ4b5iXg`kg7A=t#DzfmF^B^Lj6jA15Erumi4=xl22Do4l?+87VFdBj8OU|DiYcfp z$;i(OD9X=DO)iOf-m&Jz%+-cQ22b{NKby1W>6{HQrUo&&nJMulsl_ER#RZuusYS&x f@$s2?nI-Y@dIgoYIBatBQ%ZAE?Lg*#24V&PsckFE literal 0 HcmV?d00001 diff --git a/NO50/mid_test/spiders/__pycache__/hbin.cpython-37.pyc b/NO50/mid_test/spiders/__pycache__/hbin.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6099ec2991867f4beb036a8f2f498cd60f53965a GIT binary patch literal 576 zcmYjOy-piJ5Z=98pD#{GQc+UTxUmTm4T=&(6hUQ0a(6mub=++1L-&{6b%L#Qp@@_x zK;i`uF7gC)G?bLvCgJA+=$Sb{@ksN{-|oyeyW2}k9fopo{x!Ko`-g%j5$J58niT|K zz;hO{9R?owhYWnh_W2J#@_-LnSKQ(mHb@Dd#6xEb)vO{Y7I9#7I`Y9A@koG=*a88q zLly-PV3)S*?Cxddu+Bi~NQ}{+Js(?JqtmPOXtqqjX1~9X>yMO8X%q=r(hsQSC4yz& zInv}D7r+60(Dhua)>&ztu|M%-P z#Q`oIN?9g_lG1ggEGn4fm^ y0Yb{rZ2C+?QOE@kc;GeJuI~bq>IAt453k;&7aGu8Xu9XZw-40bacV_9L;oImUX#24 literal 0 HcmV?d00001 diff --git a/NO50/mid_test/spiders/hbin.py b/NO50/mid_test/spiders/hbin.py new file mode 100644 index 0000000..7f366fd --- /dev/null +++ b/NO50/mid_test/spiders/hbin.py @@ -0,0 +1,10 @@ +import scrapy + + +class HbinSpider(scrapy.Spider): + name = 'hbin' + allowed_domains = ['httpbin.org'] + start_urls = ['http://httpbin.org/get'] + + def parse(self, response): + print(response.text) diff --git a/NO50/scrapy.cfg b/NO50/scrapy.cfg new file mode 100644 index 0000000..40c7afa --- /dev/null +++ b/NO50/scrapy.cfg @@ -0,0 +1,11 @@ +# Automatically created by: scrapy startproject +# +# For more information about the [deploy] section see: +# https://scrapyd.readthedocs.io/en/latest/deploy.html + +[settings] +default = mid_test.settings + +[deploy] +#url = http://localhost:6800/ +project = mid_test diff --git a/README.md b/README.md index db6e141..dc45770 100644 --- a/README.md +++ b/README.md @@ -92,4 +92,6 @@ 46. [你只认识大众汽车的车标怎么能行?赶紧用python采集所有车标学习一下](https://dream.blog.csdn.net/article/details/120988302) 47. [拿爱奇艺练手Python爬虫,是在法律边缘试探吗?爬虫技巧学习](https://dream.blog.csdn.net/article/details/121007901) 48. [程序员跨行帮朋友,python爬虫之饲料添加剂数据,采集+备份](https://dream.blog.csdn.net/article/details/121028282) +49. [CSDN热榜、华为云博客都可用来练习Python scrapy 爬虫](https://dream.blog.csdn.net/article/details/121066927) +50. [纯纯的爬虫知识,python scrapy 下载中间件知多少](https://dream.blog.csdn.net/article/details/121083780) -- GitLab