I'm new to Scrapy. I have Googled around and searched in Stack Overflow, but there's no exact things I want to do. I have been struggling with these for two days.
This is what I have gotten so far for pipelines.py
. Would anyone point out what's wrong with it or show me some example code for connecting Scrapy to MySQLdb using Peewee?
from MySQLdb import *
from peewee import *
mysql_db = MySQLDatabase('nasdaq_db', user='root', passwd='')
class Quote(Model):
"""A base model that will use our MySQL database"""
time = CharField()
price = CharField()
volume = CharField()
class Meta:
database = mysql_db
db.connect()
Quote.create_table()
class RealTimeQuotePipeline(object):
def process_item(self, item, spider):
item = Quote(time=item['time'], price=item['price'], volume=['volume'])
item.save()
Run:
scrapy crawl nasdaq
Error Message:
peewee.OperationalError: (1049, "Unknown database 'nasdaq_db'")
If I change it to:
mysql_db = MySQLDatabase(db='nasdaq_db', user='root', passwd='')
There is another error message:
TypeError: __init__() takes at least 2 arguments (1 given)