0
I am trying to collect the data number of people helps in SOPT, ie my impact, to put in an api later, but is not extracting the information.
Spider:
import scrapy
class StackOverflow(scrapy.Spider):
name = 'stackoverflow'
start_urls = ['/users/17340/david']
def parse(self, response):
impact = response.xpath('//*[@id="top-cards"]/aside[3]/div/div[1]/div[1]/text()').extract()
yield impact
I’m running with command:
scrapy crawl stackoverflow
My folder structure:
├── scrapy.cfg
└── stackoverflow
├── __init__.py
├── items.py
├── middlewares.py
├── pipelines.py
├── settings.py
└── spiders
├── __init__.py
└── stackoverflow.py
Log:
2019-08-28 14:35:34 [scrapy.utils.log] INFO: Scrapy 1.7.3 started (bot: stackoverflow)
2019-08-28 14:35:34 [scrapy.utils.log] INFO: Versions: lxml 4.4.1.0, libxml2 2.9.9, cssselect 1.1.0, parsel 1.5.2, w3lib 1.21.0, Twisted 19.7.0, Python 2.7.15+ (default, Nov 27 2018, 23:36:35) - [GCC 7.3.0], pyOpenSSL 16.2.0 (OpenSSL 1.1.1c 28 May 2019), cryptography 2.7, Platform Linux-4.15.0-58-generic-x86_64-with-LinuxMint-19.2-tina
2019-08-28 14:35:34 [scrapy.crawler] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'stackoverflow.spiders', 'SPIDER_MODULES': ['stackoverflow.spiders'], 'ROBOTSTXT_OBEY': True, 'BOT_NAME': 'stackoverflow'}
2019-08-28 14:35:35 [scrapy.extensions.telnet] INFO: Telnet Password: **************
2019-08-28 14:35:35 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.memusage.MemoryUsage',
'scrapy.extensions.logstats.LogStats',
'scrapy.extensions.telnet.TelnetConsole',
'scrapy.extensions.corestats.CoreStats']
2019-08-28 14:35:35 [scrapy.middleware] INFO: Enabled downloader middlewares:
['scrapy.downloadermiddlewares.robotstxt.RobotsTxtMiddleware',
'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']
2019-08-28 14:35:35 [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']
2019-08-28 14:35:35 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2019-08-28 14:35:35 [scrapy.core.engine] INFO: Spider opened
2019-08-28 14:35:35 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2019-08-28 14:35:35 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023
2019-08-28 14:35:35 [scrapy.core.engine] DEBUG: Crawled (200) <GET /robots.txt> (referer: None)
2019-08-28 14:35:35 [scrapy.core.engine] DEBUG: Crawled (200) <GET /users/17340/david> (referer: None)
2019-08-28 14:35:35 [scrapy.core.scraper] ERROR: Spider must return Request, BaseItem, dict or None, got 'list' in <GET /users/17340/david>
2019-08-28 14:35:35 [scrapy.core.engine] INFO: Closing spider (finished)
2019-08-28 14:35:35 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 516,
'downloader/request_count': 2,
'downloader/request_method_count/GET': 2,
'downloader/response_bytes': 27101,
'downloader/response_count': 2,
'downloader/response_status_count/200': 2,
'elapsed_time_seconds': 0.684932,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2019, 8, 28, 17, 35, 35, 728976),
'log_count/DEBUG': 2,
'log_count/ERROR': 1,
'log_count/INFO': 10,
'memusage/max': 54222848,
'memusage/startup': 54222848,
'response_received_count': 2,
'robotstxt/request_count': 1,
'robotstxt/response_count': 1,
'robotstxt/response_status_count/200': 1,
'scheduler/dequeued': 1,
'scheduler/dequeued/memory': 1,
'scheduler/enqueued': 1,
'scheduler/enqueued/memory': 1,
'start_time': datetime.datetime(2019, 8, 28, 17, 35, 35, 44044)}
2019-08-28 14:35:35 [scrapy.core.engine] INFO: Spider closed (finished)
Does anyone have any idea why you’re not bringing the information?
Observing: If capturing this SOPT information is against the rules, please delete this post.
ERROR: Spider must return Request, BaseItem, dict or None, got 'list'
. Probably the selector you made is returning a list, if you debug this code, what is the value ofimpact
?– Renan Gomes
empty, but the return would be one item only, at least by the reset xpath only 1 term.
– David