打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ModuleNotFoundError: No module named scrapy.contrib

貌似我写的时候还没有搜索到其他同学写这个问题,我就写一下吧。。。。。。

我貌似在使用的时候遇到问题:写下载图片使用内置的ImagesPipeline时候

  1. Traceback (most recent call last):
  2. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\twisted\internet\defer.py", line 1418, in _inlineCallbacks
  3. result = g.send(result)
  4. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\scrapy\crawler.py", line 80, in crawl
  5. self.engine = self._create_engine()
  6. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\scrapy\crawler.py", line 105, in _create_engine
  7. return ExecutionEngine(self, lambda _: self.stop())
  8. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\scrapy\core\engine.py", line 70, in __init__
  9. self.scraper = Scraper(crawler)
  10. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\scrapy\core\scraper.py", line 71, in __init__
  11. self.itemproc = itemproc_cls.from_crawler(crawler)
  12. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\scrapy\middleware.py", line 53, in from_crawler
  13. return cls.from_settings(crawler.settings, crawler)
  14. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\scrapy\middleware.py", line 34, in from_settings
  15. mwcls = load_object(clspath)
  16. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\scrapy\utils\misc.py", line 44, in load_object
  17. mod = import_module(module)
  18. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
  19. return _bootstrap._gcd_import(name[level:], package, level)
  20. File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  21. File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  22. File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  23. File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  24. File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  25. File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  26. File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  27. File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  28. File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  29. File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  30. File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  31. ModuleNotFoundError: No module named 'scrapy.contrib'

也就是

其实报错的原因只是。。。。。他没有这个包。。。因为其实这个包在。。

from scrapy.pipelines.images import ImagesPipeline这样子

所以其实正确的写法,使用内置的是这样子写得(注意我注释的内容)

  1. ITEM_PIPELINES = {
  2. # 'tupian.pipelines.ImagePipeline': 300,
  3. 'scrapy.pipelines.images.ImagesPipeline': 300
  4. # 'scrapy.contrib.pipeline.images.ImagesPipeline':300
  5. }

这样子就可以成功使用内置的东西额。。。巨坑。

我的整个setting.py如下

  1. # -*- coding: utf-8 -*-
  2. # Scrapy settings for tupian project
  3. #
  4. # For simplicity, this file contains only settings considered important or
  5. # commonly used. You can find more settings consulting the documentation:
  6. #
  7. # https://doc.scrapy.org/en/latest/topics/settings.html
  8. # https://doc.scrapy.org/en/latest/topics/downloader-middleware.html
  9. # https://doc.scrapy.org/en/latest/topics/spider-middleware.html
  10. BOT_NAME = 'tupian'
  11. SPIDER_MODULES = ['tupian.spiders']
  12. NEWSPIDER_MODULE = 'tupian.spiders'
  13. # Crawl responsibly by identifying yourself (and your website) on the user-agent
  14. USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36'
  15. # Obey robots.txt rules
  16. ROBOTSTXT_OBEY = False
  17. # Configure maximum concurrent requests performed by Scrapy (default: 16)
  18. # CONCURRENT_REQUESTS = 32
  19. # Configure a delay for requests for the same website (default: 0)
  20. # See https://doc.scrapy.org/en/latest/topics/settings.html#download-delay
  21. # See also autothrottle settings and docs
  22. # DOWNLOAD_DELAY = 3
  23. # The download delay setting will honor only one of:
  24. # CONCURRENT_REQUESTS_PER_DOMAIN = 16
  25. # CONCURRENT_REQUESTS_PER_IP = 16
  26. # Disable cookies (enabled by default)
  27. # COOKIES_ENABLED = False
  28. # Disable Telnet Console (enabled by default)
  29. # TELNETCONSOLE_ENABLED = False
  30. # Override the default request headers:
  31. # DEFAULT_REQUEST_HEADERS = {
  32. # 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  33. # 'Accept-Language': 'en',
  34. # }
  35. # Enable or disable spider middlewares
  36. # See https://doc.scrapy.org/en/latest/topics/spider-middleware.html
  37. # SPIDER_MIDDLEWARES = {
  38. # 'tupian.middlewares.TupianSpiderMiddleware': 543,
  39. # }
  40. # Enable or disable downloader middlewares
  41. # See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html
  42. # DOWNLOADER_MIDDLEWARES = {
  43. # 'tupian.middlewares.TupianDownloaderMiddleware': 543,
  44. # }
  45. # Enable or disable extensions
  46. # See https://doc.scrapy.org/en/latest/topics/extensions.html
  47. # EXTENSIONS = {
  48. # 'scrapy.extensions.telnet.TelnetConsole': None,
  49. # }
  50. # Configure item pipelines
  51. # See https://doc.scrapy.org/en/latest/topics/item-pipeline.html
  52. ITEM_PIPELINES = {
  53. # 'tupian.pipelines.ImagePipeline': 300,
  54. 'scrapy.pipelines.images.ImagesPipeline': 300
  55. # 'scrapy.contrib.pipeline.images.ImagesPipeline':300
  56. }
  57. IMAGES_STORE ='e:/img2'
  58. # Enable and configure the AutoThrottle extension (disabled by default)
  59. # See https://doc.scrapy.org/en/latest/topics/autothrottle.html
  60. # AUTOTHROTTLE_ENABLED = True
  61. # The initial download delay
  62. # AUTOTHROTTLE_START_DELAY = 5
  63. # The maximum download delay to be set in case of high latencies
  64. # AUTOTHROTTLE_MAX_DELAY = 60
  65. # The average number of requests Scrapy should be sending in parallel to
  66. # each remote server
  67. # AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
  68. # Enable showing throttling stats for every response received:
  69. # AUTOTHROTTLE_DEBUG = False
  70. # Enable and configure HTTP caching (disabled by default)
  71. # See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
  72. # HTTPCACHE_ENABLED = True
  73. # HTTPCACHE_EXPIRATION_SECS = 0
  74. # HTTPCACHE_DIR = 'httpcache'
  75. # HTTPCACHE_IGNORE_HTTP_CODES = []
  76. # HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'

 

结果如下:e:/img2下面会有full文件夹,full下面就是下载的图片

完整代码可以去这里获取https://gitee.com/caizhw3/use-insider-ImagePipeline/tree/master

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
成功解决问题"h5py\h5r.pyx", line 145, in init h5py.h5r AttributeError: type object 'h5py.h5r.Reference' ha
OSError [WinError 123] 文件名、目录名或卷标语法不正确。 ''frozen importlib._bootstrap''
Python爬虫从入门到放弃(十七)之 Scrapy框架中Download Middleware用法
如果这篇文章还不能让你入门Python爬虫,任你伺候!
Python爬虫Scrapy入门篇
Python3.7 scrapy遇到async报错
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服