【问题标题】:I am scraping the bet3000 livescore sports website through scrapy-splash which has javascript enabled site which give me the error我正在通过scrapy-splash 抓取bet3000 livecore 体育网站,该网站启用了javascript,这给了我错误
【发布时间】:2021-02-21 01:05:42
【问题描述】:

这个蜘蛛文件

'从scrapy.spiders导入蜘蛛 从 scrapy_splash 导入 SplashRequest 从 ..items 导入 GameItem

class Splash1Spider(Spider):
    name = 'scrapy_splash_1'
    start_urls = ['https://www.livescore.bet3000.com']
    def start_requests(self):
        for url in self.start_urls:
            yield SplashRequest(url = url, callback = self.parse, args = {"wait":15})

    def parse(self, response):
        item = GameItem()
        for game in response.css('.tournament.filterable.table-block.status_result

**输出为**:

base) danish-khan@danishkhan-Latitude-E6430:/media/danish-khan/New Volume/Web_scraping/scrapy_splash/scrapy_splash_1/scrapy_splash_1$ scrapy crawl scrapy_splash_1 
2020-11-27 21:45:50 [scrapy.utils.log] INFO: Scrapy 2.0.1 started (bot: scrapy_splash_1)
2020-11-27 21:45:50 [scrapy.utils.log] INFO: Versions: lxml 4.5.0.0, libxml2 2.9.10, cssselect 1.1.0, parsel 1.5.2, w3lib 1.21.0, Twisted 20.3.0, Python 3.7.7 (default, May  7 2020, 21:25:33) - [GCC 7.3.0], pyOpenSSL 19.1.0 (OpenSSL 1.1.1d  10 Sep 2019), cryptography 2.8, Platform Linux-5.4.0-47-generic-x86_64-with-debian-bullseye-sid
2020-11-27 21:45:50 [scrapy.utils.log] DEBUG: Using reactor: twisted.internet.epollreactor.EPollReactor
2020-11-27 21:45:50 [scrapy.crawler] INFO: Overridden settings:
{'BOT_NAME': 'scrapy_splash_1',
 'DUPEFILTER_CLASS': 'scrapy_splash.SplashAwareDupeFilter',
 'HTTPCACHE_STORAGE': 'scrapy_splash.SplashAwareFSCacheStorage',
 'NEWSPIDER_MODULE': 'scrapy_splash_1.spiders',
 'SPIDER_MODULES': ['scrapy_splash_1.spiders']}
2020-11-27 21:45:50 [scrapy.extensions.telnet] INFO: Telnet Password: aff4870d4448e4b9
2020-11-27 21:45:50 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
 'scrapy.extensions.telnet.TelnetConsole',
 'scrapy.extensions.memusage.MemoryUsage',
 'scrapy.extensions.logstats.LogStats']
2020-11-27 21:45:50 [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.redirect.RedirectMiddleware',
 'scrapy.downloadermiddlewares.cookies.CookiesMiddleware',
 'scrapy_splash.SplashCookiesMiddleware',
 'scrapy_splash.SplashMiddleware',
 'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware',
 'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware',
 'scrapy.downloadermiddlewares.stats.DownloaderStats']
2020-11-27 21:45:50 [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-11-27 21:45:50 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2020-11-27 21:45:50 [scrapy.core.engine] INFO: Spider opened
2020-11-27 21:45:50 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2020-11-27 21:45:50 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023
2020-11-27 21:45:50 [py.warnings] WARNING: /home/danish-khan/miniconda3/lib/python3.7/site-packages/scrapy_splash/request.py:41: ScrapyDeprecationWarning: Call to deprecated function to_native_str. Use to_unicode instead.
  url = to_native_str(url)

2020-11-27 21:46:06 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.livescore.bet3000.com via http://localhost:8050/render.html> (referer: None)
2020-11-27 21:46:06 [scrapy.core.engine] INFO: Closing spider (finished)
2020-11-27 21:46:06 [scrapy.statscollectors] INFO: Dumping Scrapy stats:

我不明白为什么会发生此错误,我检查了 css 选择器但无法正常工作

【问题讨论】:

    标签: python web-scraping scrapy scrapy-splash


    【解决方案1】:

    您的代码没有错误。两种情况中的任何一种都在发生:

    1. 您收到的响应不正确或未完全呈现。
    2. 您的选择器不正确。

    你可以做的是在你的 for 循环之前放置一个断点,看看响应是否真的包含你试图抓取的数据。

    【讨论】:

    • 断点我不懂就给我解释一下。
    • 您的代码中没有错误,但您的响应不包含您要查找的元素。尝试将响应的正文保存到 html 文件中,然后如果您不想使用断点添加调试,则可以检查该 html 文件。
    猜你喜欢
    • 2021-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 2021-10-14
    • 2011-03-22
    相关资源
    最近更新 更多