无法在scrapy中导入项目 [英] Unable to import items in scrapy

查看:38
本文介绍了无法在scrapy中导入项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的蜘蛛,按照入门指南中的说明进行操作,但由于某种原因,尝试将我的项目导入我的蜘蛛会返回错误.蜘蛛和物品代码如下所示:

I have a very basic spider, following the instructions in the getting started guide, but for some reason, trying to import my items into my spider returns an error. Spider and items code is shown below:

from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector

from myProject.items import item

class MyProject(BaseSpider):
    name = "spider"
    allowed_domains = ["website.com"]
    start_urls = [
        "website.com/start"
    ]

    def parse(self, response):
        print response.body

from scrapy.item import Item, Field

class ProjectItem(Item):
    title = Field()

当我运行此代码时,scrapy 要么找不到我的蜘蛛,要么无法导入我的项目文件.这里发生了什么?这应该是一个真正运行正确的例子?

When I run this code scrapy either can't find my spider, or can't import my items file. What's going on here? This should be a really example to run right?

推荐答案

我在使用 scrapy 时也遇到过几次这种情况.您可以在 Python 模块的开头添加这一行:

I also had this several times while working with scrapy. You could add at the beginning of your Python modules this line:

from __future__ import absolute_import

更多信息在这里:

这篇关于无法在scrapy中导入项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆