V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
llhh
V2EX  ›  问与答

scrapy 爬虫错误求助

  •  
  •   llhh · 2014-11-05 10:53:22 +08:00 · 3028 次点击
    这是一个创建于 3480 天前的主题,其中的信息可能已经有所发展或是发生改变。
    错误:
    ImportError: No module named items

    程序:

    items.py代码:
    # Define here the models for your scraped items
    #
    # See documentation in:
    # http://doc.scrapy.org/en/latest/topics/items.html

    from scrapy.item import Item, Field

    class XsItem(Item):
    # define the fields for your item here like:
    # name = Field()
    url = Field()

    xs.py代码:
    from scrapy.contrib.spiders import CrawlSpider, Rule
    from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
    from scrapy.selector import Selector

    from xs.items import XsItem

    class XsSpider(CrawlSpider):
    name = 'xs'
    allowed_domains = ['bbs.uc.cn']
    start_urls = ['http://bbs.uc.cn']

    rules = (
    Rule(SgmlLinkExtractor(allow=('\thread-\d+-\d-\d.html', )),
    callback='parse_page', follow=True),
    )

    def parse_page(self, response):
    item = XsItem()
    sel = Selector(response)
    item['url'] = response.url
    return item
    6 条回复    2014-11-06 13:58:09 +08:00
    Gymgle
        1
    Gymgle  
       2014-11-05 11:57:04 +08:00
    注释掉 xs.py 中的 from xs.items import XsItem 试试
    roricon
        2
    roricon  
       2014-11-05 13:08:25 +08:00
    贴一下你的目录结构。有__init__.py这个文件么?
    llhh
        3
    llhh  
    OP
       2014-11-05 13:27:30 +08:00
    @roricon 有的。
    yiding
        4
    yiding  
       2014-11-05 14:13:01 +08:00
    @llhh 有这个文件,你里面有没有 import xs 呢
    没有这个module,就检查一下是名称有没有弄错,如果没有,那结构有没有错
    或者执行的目录环境不同也可能有这种问题啊

    from xs.items import Xsitem
    从你贴的代码看xs是文件,但是xs.items里的xs给人的感觉却像是文件夹名呢
    最好还是像2L说的,贴一下目录结构看看
    Gymgle
        5
    Gymgle  
       2014-11-06 13:31:46 +08:00   ❤️ 1
    http://wsky.org/archives/191.html 这里是一个爬取cnbeta新闻的实例
    llhh
        6
    llhh  
    OP
       2014-11-06 13:58:09 +08:00
    @Gymgle 就是按照他的来做的,拿下来成功了。但我的错误。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3251 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:37 · PVG 21:37 · LAX 06:37 · JFK 09:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.