注册 登录
编程论坛 Python论坛

scrapy框架spider文件中的item类从哪导入

肥科的竹子 发布于 2019-09-10 11:58, 2060 次点击
spider文件中 item 的类应该从哪里导入?
#tx.py     spider文件
# -*- coding: utf-8 -*-
import scrapy
from  ***.items import TencentItem #此处的item的类应该从哪里导入?或者说要导入 item 的类此处应该怎么写

class TxSpider(scrapy.Spider):
    name = 'tx'
    allowed_domains = ['https://careers.,ot_40001002,ot_40001003,ot_40001004,ot_40001005,ot_40001006&index=']
    start_urls = ['http://https://careers.,ot_40001002,ot_40001003,ot_40001004,ot_40001005,ot_40001006&index=1']

    def parse(self, response):
        pass
'''
在 cmd 中创建项目命令为
scrapy startproject tencent

    创建出的项目中的 items.py 文件中有
        class TencentItem(scrapy.Item):
            pass
        )

创建spider 命令为
scrapy genspider tx "https://careers.

求助:在spider文件中如何导入 TencentItem
'''
1 回复
#2
肥科的竹子2019-09-17 09:30
问题已解决  相对包的导入   
首先                       import sys
然后添加要导入文件的路径   sys.path.append("C:\桌面\新建文件夹\tencent\tencent")
然后                       from items import TencentItem
1