Pychart: How to Solve myspyder.items import myitem Error

Problem description

In items. Py , customize the item method.

# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html

import scrapy

class MyspiderItem(scrapy.Item):
    # define the fields for your item here like:
    name = scrapy.Field()
    title = scrapy.Field()
    desc = scrapy.Field()
    RD_achievements = scrapy.Field()

We need to introduce this method into the sweep, which is the item method defined by ourselves in the sweep, but we need to reference it in the spider in the sweep, so we need to add a string of code to change our introduction method.

Error reported in pychart from myspyder.items import itcastitem :

Original import method:

import scrapy
from crawlAdvanced.myspider.myspider.items import MyspiderItem
"""
 scrapy crawl itcast --nolog
"""

from crawlAdvanced.myspider.myspider.items import MyspiderItem ModuleNotFoundError: No module named 'crawlAdvanced'

Solution 1

Change from myspider.items import myitem to from.. items import myitem

In a package, peers use . and parents use ..

Maybe the computer doesn’t know which file you’re talking about. After all, the two file names are the same( I don’t understand. I hope the boss can correct it!)

scrapy startproject mySpider

scrapy crawl mySpider

scrapy crawl mySpider -o teachers.json

Solution 2

If the error is still reported, you can refer to the following methods: (my error is solved by using the above method)

# -*- coding: utf-8 -*-
 
#The original python method of introducing scrapy class is wrong, please reintroduce it with this method
from __future__ import absolute_import
# is the above code
 
import scrapy
 
from selenium import webdriver
from  scrapy_splash import SplashMiddleware
from scrapy_splash import SplashRequest
import pymysql
from ..item360 import Jc360Item

Read More: