【问题标题】:How to set scrapy IMAGES_STORE relative path如何设置scrapy IMAGES_STORE 相对路径
【发布时间】:2013-06-28 08:03:57
【问题描述】:

我正在尝试将 IMAGES_STORE 设置为相对路径,但出现错误,如果我将 IMAGES_STORE 指定为完整路径,它工作正常 /home/vaibhav/scrapyprog/comparison/eScraperInterface/images

我得到的错误是link 实际上它给了我RuntimeError: OSError: [Errno 20] Not a directory: '/tmp/eScraper-1371463750-Lm8HLh.egg/images' 错误但是如果我设置完整的 IMAGE_STORE 路径它工作正常有人可以告诉我如何指定相对路径...因为我需要在各种系统上部署这个项目...这就是为什么我需要相对路径....

import os
#------------------------------------------------------------------------------ 

projectDirPath = os.path.abspath(os.path.dirname((os.path.dirname(__file__))))
imagesDIRPath =  projectDirPath + "/images"

BOT_NAME = 'eScraper'
DOWNLOADER_DEBUG = True
CONCURRENT_REQUESTS = 200
AUTOTHROTTLE_DEBUG = True
AUTOTHROTTLE_ENABLED= True
DEPTH_STATS_VERBOSE = True

SPIDER_MODULES = ['eScraper.spiders']
NEWSPIDER_MODULE = 'eScraper.spiders'
COMMANDS_MODULE = 'eScraper.commands'
ITEM_PIPELINES = ['eScraper.pipelines.EscraperPipeline',
                  'eScraper.pipelines.MySQLStorePipeline']

IMAGES_STORE = imagesDIRPath


DOWNLOADER_MIDDLEWARES = {
                          'eScraper.rotate_useragent.RotateUserAgentMiddleware' :400,
                          'scrapy.contrib.downloadermiddleware.useragent.UserAgentMiddleware' : None
                          }


#------------------------------------------------------------------------------

我的项目结构:

├── eScraperInterface
│   ├── build
│   │   ├── bdist.linux-i686
│   │   └── lib.linux-i686-2.7
│   │       ├── eScraper
│   │       │   ├── commands
│   │       │   │   ├── __init__.py
│   │       │   │   └── runAllSpiders.py
│   │       │   ├── __init__.py
│   │       │   ├── items.py
│   │       │   ├── pipelines.py
│   │       │   ├── rotate_useragent.py
│   │       │   ├── settings.py
│   │       │   ├── spiders
│   │       │   └── userAgentList.py
│   │       ├── eScraperInterface
│   │       │   ├── __init__.py
│   │       │   ├── settings.py
│   │       │   ├── urls.py
│   │       │   └── wsgi.py
│   │       └── eScraperInterfaceApp
│   │           ├── __init__.py
│   │           ├── models.py
│   │           ├── tests.py
│   │           └── views.py
│   ├── checkImageExist.py
│   ├── eScraper
│   │   ├── commands
│   │   │   ├── __init__.py
│   │   │   ├── __init__.pyc
│   │   │   ├── runAllSpiders.py
│   │   │   └── runAllSpiders.pyc
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── items.py
│   │   ├── items.pyc
│   │   ├── pipelines.py
│   │   ├── pipelines.pyc
│   │   ├── rotate_useragent.py
│   │   ├── rotate_useragent.pyc
│   │   ├── settings.py
│   │   ├── settings.py~
│   │   ├── settings.pyc
│   │   ├── spiders
│   │   ├── userAgentList.py
│   │   └── userAgentList.pyc
│   ├── eScraperInterface
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── settings.py
│   │   ├── settings.pyc
│   │   ├── urls.py
│   │   ├── urls.pyc
│   │   ├── wsgi.py
│   │   └── wsgi.pyc
│   ├── eScraperInterfaceApp
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── models.py
│   │   ├── models.py~
│   │   ├── models.pyc
│   │   ├── tests.py
│   │   └── views.py
│   ├── images
│   ├── __init__.py
│   ├── manage.py
│   ├── project.egg-info
│   │   ├── dependency_links.txt
│   │   ├── entry_points.txt
│   │   ├── PKG-INFO
│   │   ├── SOURCES.txt
│   │   └── top_level.txt
│   ├── scrapy.cfg
│   └── setup.py
├── README.txt
└── README.txt~

【问题讨论】:

    标签: python scrapy scrapyd


    【解决方案1】:

    假设您从eScraperInterface/eScraper/settings.py 提供了settings.py

    CUR_DIR = os.path.dirname(os.path.realpath(__file__))
    IMAGES_STORE = os.path.join(CUR_DIR, '..', 'images')
    

    希望对您有所帮助。

    【讨论】:

    • 那么,请在问题中包含您的项目结构,谢谢。
    • @user2217267,更新了答案:现在为images 上一级。请检查。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-18
    • 2010-09-21
    • 1970-01-01
    • 2013-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多