Note that there are some explanatory texts on larger screens.

plurals
  1. POScrapy and Django import error
    primarykey
    data
    text
    <p>When I am calling Spider through a Python script, it is giving me an <code>ImportError</code>:</p> <pre><code>ImportError: No module named app.models </code></pre> <p>My <code>items.py</code> is like this:</p> <pre><code>from scrapy.item import Item, Field from scrapy.contrib.djangoitem import DjangoItem from app.models import Person class aqaqItem(DjangoItem): django_model=Person pass </code></pre> <p>My <code>settings.py</code> is like this:</p> <pre><code># # For simplicity, this file contains only the most important settings by # default. All the other settings are documented here: # # http://doc.scrapy.org/topics/settings.html # BOT_NAME = 'aqaq' BOT_VERSION = '1.0' SPIDER_MODULES = ['aqaq.spiders'] NEWSPIDER_MODULE = 'aqaq.spiders' USER_AGENT = '%s/%s' % (BOT_NAME, BOT_VERSION) ITEM_PIPELINES = [ 'aqaq.pipelines.JsonWithEncodingPipeline'] import sys import os c=os.getcwd() os.chdir("../../myweb") d=os.getcwd() os.chdir(c) sys.path.insert(0, d) # Setting up django's settings module name. # This module is located at /home/rolando/projects/myweb/myweb/settings.py. import os os.environ['DJANGO_SETTINGS_MODULE'] = 'myweb.settings' </code></pre> <p>My Python script to call the spider is like this:</p> <pre><code>from twisted.internet import reactor from scrapy.crawler import Crawler from scrapy import log, signals from final.aqaq.aqaq.spiders.spider import aqaqspider from scrapy.utils.project import get_project_settings def stop_reactor(): reactor.stop() spider = aqaqspider(domain='aqaq.com') settings = get_project_settings() crawler = Crawler(settings) crawler.signals.connect(reactor.stop, signal=signals.spider_closed) crawler.configure() crawler.crawl(spider) crawler.start() log.start() reactor.run() </code></pre> <p>My directory structure is like this:</p> <pre><code>. |-- aqaq | |-- aqaq | | |-- call.py | | |-- __init__.py | | |-- __init__.pyc | | |-- items.py | | |-- items.pyc | | |-- pipelines.py | | |-- pipelines.pyc | | |-- settings.py | | |-- settings.pyc | | `-- spiders | | |-- aqaq.json | | |-- __init__.py | | |-- __init__.pyc | | |-- item.json | | |-- spider.py | | |-- spider.pyc | | `-- url | |-- call.py | |-- call_spider.py | `-- scrapy.cfg |-- mybot | |-- mybot | | |-- __init__.py | | |-- items.py | | |-- pipelines.py | | |-- settings.py | | `-- spiders | | |-- example.py | | `-- __init__.py | `-- scrapy.cfg `-- myweb |-- app | |-- admin.py | |-- admin.pyc | |-- __init__.py | |-- __init__.pyc | |-- models.py | |-- models.pyc | |-- tests.py | `-- views.py |-- manage.py `-- myweb |-- file |-- __init__.py |-- __init__.pyc |-- settings.py |-- settings.pyc |-- urls.py |-- urls.pyc |-- wsgi.py `-- wsgi.pyc </code></pre> <p>Please help me as I am new to Scrapy.</p> <p>i am real confused i tried importing </p> <pre><code>import os os.environ['DJANGO_SETTINGS_MODULE'] = 'myweb.settings </code></pre> <p>in my script at the top new error came that </p> <pre><code>get_project_settings is invalid </code></pre> <p>also my scarapy version is 18</p> <p>Thank you all i got the solution</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload