example config File – breit_work.py:
# -*- coding: utf-8 -*-
import scrapy
class BreitWorkSpider(scrapy.Spider):
name = 'breit.work'
allowed_domains = ['breit.work']
start_urls = ['https://breit.work/']
def parse(self, response):
for title in response.css('h3'):
yield {'title 1': title.css('a ::text').get()}
for title in response.css('h2'):
yield {'title 2': title.css('a ::text').get()}
for next_page in response.css('a.next-posts-link'):
yield response.follow(next_page, self.parse)
run with:
scrapy runspider breit_work.py
example output:
2020-10-13 11:05:26 [scrapy.utils.log] INFO: Scrapy 1.8.0 started (bot: scrapybot)
2020-10-13 11:05:26 [scrapy.utils.log] INFO: Versions: lxml 4.5.2.0, libxml2 2.9.10, cssselect 1.1.0, parsel 1.6.0, w3lib 1.22.0, Twisted 20.3.0, Python 2.7.16 (default, Oct 10 2019, 22:02:15) - [GCC 8.3.0], pyOpenSSL 19.1.0 (OpenSSL 1.1.1d 10 Sep 2019), cryptography 2.6.1, Platform Linux-4.19.0-10-amd64-x86_64-with-debian-10.5
2020-10-13 11:05:26 [scrapy.crawler] INFO: Overridden settings: {'SPIDER_LOADER_WARN_ONLY': True}
2020-10-13 11:05:26 [scrapy.extensions.telnet] INFO: Telnet Password: ~not4YouNoob*
2020-10-13 11:05:26 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.memusage.MemoryUsage',
'scrapy.extensions.logstats.LogStats',
'scrapy.extensions.telnet.TelnetConsole',
'scrapy.extensions.corestats.CoreStats']
2020-10-13 11:05:26 [scrapy.middleware] INFO: Enabled downloader middlewares:
['scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware',
'scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware',
'scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware',
'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware',
'scrapy.downloadermiddlewares.retry.RetryMiddleware',
'scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware',
'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware',
'scrapy.downloadermiddlewares.redirect.RedirectMiddleware',
'scrapy.downloadermiddlewares.cookies.CookiesMiddleware',
'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware',
'scrapy.downloadermiddlewares.stats.DownloaderStats']
2020-10-13 11:05:26 [scrapy.middleware] INFO: Enabled spider middlewares:
['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware',
'scrapy.spidermiddlewares.offsite.OffsiteMiddleware',
'scrapy.spidermiddlewares.referer.RefererMiddleware',
'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware',
'scrapy.spidermiddlewares.depth.DepthMiddleware']
2020-10-13 11:05:26 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2020-10-13 11:05:26 [scrapy.core.engine] INFO: Spider opened
2020-10-13 11:05:26 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2020-10-13 11:05:26 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023
2020-10-13 11:05:26 [scrapy.downloadermiddlewares.redirect] DEBUG: Redirecting (301) to <GET https://www.breit.work/> from <GET https://breit.work/>
2020-10-13 11:05:26 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.breit.work/> (referer: None)
2020-10-13 11:05:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.breit.work/>
{'title 1': u'Impress'}
2020-10-13 11:05:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.breit.work/>
{'title 2': u'Boston Dynamics spielt mit dem Krieg'}
2020-10-13 11:05:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.breit.work/>
{'title 2': u'It\u2019s done \u2026 Bye bye Britain !'}
2020-10-13 11:05:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.breit.work/>
{'title 2': u'Play with redis-server'}
2020-10-13 11:05:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.breit.work/>
{'title 2': u'dd with a nice progress indicator'}
2020-10-13 11:05:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.breit.work/>
{'title 2': u'XEN 4.11 on Debian 10'}
2020-10-13 11:05:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.breit.work/>
{'title 2': u'Redis 6.0 is out'}
2020-10-13 11:05:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.breit.work/>
{'title 2': u'Setup Pageflow Storytelling with NGINX & Lets Encrypt'}
2020-10-13 11:05:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.breit.work/>
{'title 2': u'MySQL 8 \u2013 create Database with own user'}
2020-10-13 11:05:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.breit.work/>
{'title 2': u'Schade REAL, das war es leider'}
2020-10-13 11:05:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.breit.work/>
{'title 2': u't\xe4gliche Mysql-Backups'}
2020-10-13 11:05:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.breit.work/>
{'title 2': u'Setup Redis-Server 6.0.0 Beta'}
2020-10-13 11:05:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.breit.work/>
{'title 2': u'Lustiges beim Server Einrichten'}
2020-10-13 11:05:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.breit.work/>
{'title 2': None}
2020-10-13 11:05:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.breit.work/>
{'title 2': None}
2020-10-13 11:05:27 [scrapy.core.engine] INFO: Closing spider (finished)
2020-10-13 11:05:27 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 422,
'downloader/request_count': 2,
'downloader/request_method_count/GET': 2,
'downloader/response_bytes': 26080,
'downloader/response_count': 2,
'downloader/response_status_count/200': 1,
'downloader/response_status_count/301': 1,
'elapsed_time_seconds': 0.361133,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2020, 10, 13, 11, 5, 27, 61229),
'item_scraped_count': 15,
'log_count/DEBUG': 17,
'log_count/INFO': 10,
'memusage/max': 51576832,
'memusage/startup': 51576832,
'response_received_count': 1,
'scheduler/dequeued': 2,
'scheduler/dequeued/memory': 2,
'scheduler/enqueued': 2,
'scheduler/enqueued/memory': 2,
'start_time': datetime.datetime(2020, 10, 13, 11, 5, 26, 700096)}
2020-10-13 11:05:27 [scrapy.core.engine] INFO: Spider closed (finished)
0 Antworten auf “Playtime with scrapy”