【发布时间】:2016-09-24 21:58:43
【问题描述】:
我有一个 django 项目和一个 scrapy 项目
我想将 django 模型导入到 scrapy 项目中。
这是我的蜘蛛:
import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
import sys
sys.path.append('/home/ubuntu/venv/dict')
from dmmactress.models import EnActress
class JpnNameSpider(scrapy.Spider):
name = jp_name
allowed_domains = ['enjoyjapan.co.kr']
rx = EnActress.objects.values_list('name', flat=True)
rxs = rx.reverse()
start_urls = ['http://enjoyjapan.co.kr/how_to_read_japanese_name.php?keyword=%s' % jp for jp in rxs]
def parse(self, response):
for sel in response('//*[@id="contents"]/div/div[1]/div/div[1]'):
item = JapanessItem()
item['koname'] = sel.xpath('div[4]/div[1]()/text()').extract()
item['jpname'] = sel.xpath('div[2]/div[1]()/text()').extract()
yield item
next_page = response.css('#contents > div > div:nth-child(4) > div > a::attr(href)').extract_first()
if naxt_page is not None:
next_page = response.urljoin(next_page)
yield scrapy.Request(next_page, self.parse)
我在运行蜘蛛时遇到了错误
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configure.
-- 谁能帮我看看我做错了什么?
提前致谢!
【问题讨论】:
-
Django 使用它的 settings.py 和 manage.py 来做各种魔术来提供模型和数据库之间的粘合剂。如果您只是导入模型文件,那么您将度过一段糟糕的时光。可以反过来坐吗?