Issue
I want to be a code for analysing a bet graphics. What the error has ocurred in the log ? I took the test with other famous sites and I couldn't get a response either.
scrapy runspider av/av/spiders/av.py
2022-03-05 14:46:38 [scrapy.utils.log] INFO: Scrapy 2.6.1 started (bot: scrapybot)
2022-03-05 14:46:38 [scrapy.utils.log] INFO: Versions: lxml 4.8.0.0, libxml2 2.9.12, cssselect 1.1.0, parsel 1.6.0, w3lib 1.22.0, Twisted 22.2.0, Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)], pyOpenSSL 22.0.0 (OpenSSL 1.1.1m 14 Dec 2021), cryptography 36.0.1, Platform Windows-10-10.0.22000-SP0
2022-03-05 14:46:38 [scrapy.crawler] INFO: Overridden settings:
{'SPIDER_LOADER_WARN_ONLY': True}
2022-03-05 14:46:38 [scrapy.utils.log] DEBUG: Using reactor: twisted.internet.selectreactor.SelectReactor
2022-03-05 14:46:38 [scrapy.extensions.telnet] INFO: Telnet Password: a318c628cfaf76a9
2022-03-05 14:46:38 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
'scrapy.extensions.telnet.TelnetConsole',
'scrapy.extensions.logstats.LogStats']
2022-03-05 14:46:38 [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']
2022-03-05 14:46:38 [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']
2022-03-05 14:46:38 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2022-03-05 14:46:38 [scrapy.core.engine] INFO: Spider opened
2022-03-05 14:46:38 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2022-03-05 14:46:38 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023
2022-03-05 14:46:39 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://aviator-next.spribegaming.com/?user=896541&token=2c5aa7d41630609ddf82e58655f7299e3106a6377b678d50740ab7aa5925afdf&lang=pt¤cy=BRL&return_url=&operator=demo&jurisdiction=CW> (referer: None)
2022-03-05 14:46:39 [scrapy.core.scraper] ERROR: Spider error processing <GET https://aviator-next.spribegaming.com/?user=896541&token=2c5aa7d41630609ddf82e58655f7299e3106a6377b678d50740ab7aa5925afdf&lang=pt¤cy=BRL&return_url=&operator=demo&jurisdiction=CW> (referer: None)
Traceback (most recent call last):
File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\twisted\internet\defer.py", line 857, in _runCallbacks
current.result = callback( # type: ignore[misc]
File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\scrapy\spiders\__init__.py", line 67, in _parse
return self.parse(response, **kwargs)
File "C:\Users\Antônio\Desktop\av\av\av\spiders\av.py", line 9, in parse
title = response.css('title::text').extract.first()
AttributeError: 'function' object has no attribute 'first'
2022-03-05 14:46:39 [scrapy.core.engine] INFO: Closing spider (finished)
2022-03-05 14:46:39 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 375,
'downloader/request_count': 1,
'downloader/request_method_count/GET': 1,
'downloader/response_bytes': 7445,
'downloader/response_count': 1,
'downloader/response_status_count/200': 1,
'elapsed_time_seconds': 1.152582,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2022, 3, 5, 17, 46, 39, 869740),
'httpcompression/response_bytes': 9849,
'httpcompression/response_count': 1,
'log_count/DEBUG': 2,
'log_count/ERROR': 1,
'log_count/INFO': 10,
'response_received_count': 1,
'scheduler/dequeued': 1,
'scheduler/dequeued/memory': 1,
'scheduler/enqueued': 1,
'scheduler/enqueued/memory': 1,
'spider_exceptions/AttributeError': 1,
'start_time': datetime.datetime(2022, 3, 5, 17, 46, 38, 717158)}
2022-03-05 14:46:39 [scrapy.core.engine] INFO: Spider closed (finished)
Above is the error log, below is my code, a very simple code just to try to receive the test information from the page
import scrapy
class AvSpider(scrapy.Spider):
name = 'av'
allowed_domains = ['aviator-next.spribegaming.com']
start_urls = ['https://aviator-next.spribegaming.com/?user=896541&token=2c5aa7d41630609ddf82e58655f7299e3106a6377b678d50740ab7aa5925afdf&lang=pt¤cy=BRL&return_url=&operator=demo&jurisdiction=CW']
def parse(self, response):
title = response.css('title::text').extract.first()
print(title)
pass
I want to receive a simple title, if it works i want to be start my project.
Solution
If you want to extract the first thing that matches, use the method extract_first()
import scrapy
class AvSpider(scrapy.Spider):
name = 'av'
allowed_domains = ['aviator-next.spribegaming.com']
start_urls = ['https://aviator-next.spribegaming.com/?user=896541&token=2c5aa7d41630609ddf82e58655f7299e3106a6377b678d50740ab7aa5925afdf&lang=pt¤cy=BRL&return_url=&operator=demo&jurisdiction=CW']
def parse(self, response):
title = response.css('title::text').extract_first()
print(title)
pass
This is currently working here for me and printing 'Aviator' as the title.
Answered By - Arson 0
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.