问题描述
我最近在学习“分布式蜘蛛”,你可以看到我的截图或如下(错误) Screenshot1
2021-03-29 15:29:56 [twisted] CRITICAL:
Traceback (most recent call last):
File "c:\program files (x86)\python\lib\site-packages\twisted\internet\defer.py",line 1445,in _inlineCallbacks
result = current_context.run(g.send,result)
File "c:\program files (x86)\python\lib\site-packages\scrapy\crawler.py",line 87,in crawl
self.engine = self._create_engine()
File "c:\program files (x86)\python\lib\site-packages\scrapy\crawler.py",line 101,in _create_engine
return ExecutionEngine(self,lambda _: self.stop())
File "c:\program files (x86)\python\lib\site-packages\scrapy\core\engine.py",line 70,in __init__
self.scraper = Scraper(crawler)
File "c:\program files (x86)\python\lib\site-packages\scrapy\core\scraper.py",line 71,in __init__
self.itemproc = itemproc_cls.from_crawler(crawler)
File "c:\program files (x86)\python\lib\site-packages\scrapy\middleware.py",line 53,in from_crawler
return cls.from_settings(crawler.settings,crawler)
File "c:\program files (x86)\python\lib\site-packages\scrapy\middleware.py",line 34,in from_settings
mwcls = load_object(clspath)
File "c:\program files (x86)\python\lib\site-packages\scrapy\utils\misc.py",line 62,in load_object
mod = import_module(module)
File "c:\program files (x86)\python\lib\importlib\__init__.py",line 127,in import_module
return _bootstrap._gcd_import(name[level:],package,level)
File "<frozen importlib._bootstrap>",line 1014,in _gcd_import
File "<frozen importlib._bootstrap>",line 991,in _find_and_load
File "<frozen importlib._bootstrap>",line 961,in _find_and_load_unlocked
File "<frozen importlib._bootstrap>",line 219,in _call_with_frames_removed
File "<frozen importlib._bootstrap>",line 973,in _find_and_load_unlocked
ModuleNotFoundError: No module named 'scrapy-redis'
终端显示错误:ModuleNotFoundError: No module named 'scrapy-redis' 但我已经安装了模块Screenshot of cmd
这是我的蜘蛛
import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider,Rule
from distributePro.items import distributeproItem
#Try to import the path,but fail
import sys
sys.path.append('C:\Program Files (x86)\python\Lib\site-packages\scrapy_redis')
from scrapy_redis.spiders import RedisCrawlSpider
class disSpider(RedisCrawlSpider):
name = 'distribute'
#allowed_domains = ['www.xxx.comxxx.com']
# start_urls = ['http://www.xxx.comxxx.com/']
redis_key = 'sun'
rules = (
Rule(LinkExtractor(allow=r'id=1&page=\d+'),callback='parse_item',follow=True),)
def parse_item(self,response):
li_list = response.xpath('/html/body/div[2]/div[3]/ul[2]/li')
for li in li_list:
news_num = li.xpath('./span[1]/text()').extract_first()
news_title = li.xpath('span[3]/a/text()').extract_first()
item = distributeproItem()
item['news_num'] = news_num
item['news_title'] = news_title
yield item
我的设置如下
# Scrapy settings for distributePro project
#
# For simplicity,this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
# https://docs.scrapy.org/en/latest/topics/settings.html
# https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
# https://docs.scrapy.org/en/latest/topics/spider-middleware.html
BOT_NAME = 'distributePro'
SPIDER_MODULES = ['distributePro.spiders']
NEWSPIDER_MODULE = 'distributePro.spiders'
USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/89.0.4389.90 Safari/537.36'
# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'distributePro (+http://www.yourdomain.com)'
# Obey robots.txt rules
ROBOTSTXT_OBEY = False
# Configure maximum concurrent requests performed by Scrapy (default: 16)
#CONCURRENT_REQUESTS = 32
# Configure a delay for requests for the same website (default: 0)
# See https://docs.scrapy.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
#DOWNLOAD_DELAY = 3
# The download delay setting will honor only one of:
#CONCURRENT_REQUESTS_PER_DOMAIN = 16
#CONCURRENT_REQUESTS_PER_IP = 16
# disable cookies (enabled by default)
#COOKIES_ENABLED = False
# disable Telnet Console (enabled by default)
#TELNETCONSOLE_ENABLED = False
# Override the default request headers:
#DEFAULT_REQUEST_HEADERS = {
# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',# 'Accept-Language': 'en',#}
# Enable or disable spider middlewares
# See https://docs.scrapy.org/en/latest/topics/spider-middleware.html
#SPIDER_MIDDLEWARES = {
# 'distributePro.middlewares.distributeproSpiderMiddleware': 543,#}
# Enable or disable downloader middlewares
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
#DOWNLOADER_MIDDLEWARES = {
# 'distributePro.middlewares.distributeprodownloaderMiddleware': 543,#}
# Enable or disable extensions
# See https://docs.scrapy.org/en/latest/topics/extensions.html
#EXTENSIONS = {
# 'scrapy.extensions.telnet.TelnetConsole': None,#}
# Configure item pipelines
# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html
# ITEM_PIPELInes = {
# 'distributePro.pipelines.distributeproPipeline': 300,# }
# Enable and configure the AutoThrottle extension (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/autothrottle.html
#AUTOTHRottLE_ENABLED = True
# The initial download delay
#AUTOTHRottLE_START_DELAY = 5
# The maximum download delay to be set in case of high latencies
#AUTOTHRottLE_MAX_DELAY = 60
# The average number of requests Scrapy should be sending in parallel to
# each Remote Server
#AUTOTHRottLE_TARGET_CONCURRENCY = 1.0
# Enable showing throttling stats for every response received:
#AUTOTHRottLE_DEBUG = False
# Enable and configure HTTP caching (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
#HTTPCACHE_ENABLED = True
#HTTPCACHE_EXPIRATION_SECS = 0
#HTTPCACHE_DIR = 'httpcache'
#HTTPCACHE_IGnorE_HTTP_CODES = []
#HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'
ITEM_PIPELInes={
'scrapy-redis.pipelines.RedisPipeline':400
}
DUPEFILTER_CLASS = "scrapy_redis.dupefilter.RFPDuperFilter"
SCHEDULER = "scrapy_redis.scheduler.Scheduler"
SCHEDULER_PERSIST = "True"
SCHEDULER_QUEUE_CLASS = 'scrapy_redis.queue.PriorityQueue'
REdis_HOST = '127.0.0.1'
REdis_PORT = 6379
我该怎么办? 谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)