我目前正在使用Scrapy开发一个webscraper,数据存储在Django中。当我使用自定义命令启动刮板时。但我被这个错误困住了:
AttributeError: 'Settings' object has no attribute 'setmodule'
我检查了设置文件,找不到Setmodule属性
我的自定义命令文件:
/webscraper/management/commands/crawl-test.py
import os
# Django requirements
from django.core.management.base import BaseCommand
from django.conf import settings
# scrapy requirements
import scrapy
from webscraper.webscraper.spiders.WebSpider import WebSpider
from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings
class Command(BaseCommand):
help = "Web Scraper"
def handle(self, *args, **options):
process = CrawlerProcess(get_project_settings())
os.environ['SCRAPY_SETTINGS_MODULE'] = 'webscraper.settings'
settings_module_path = os.environ['SCRAPY_SETTINGS_MODULE']
settings.setmodule(settings_module_path, priority='project')
process = CrawlerProcess(get_project_settings())
process.crawl(WebSpider)
process.start()
如果您需要更多信息,请留言
目前没有回答
相关问题 更多 >
编程相关推荐