我正在Scrapy中构建一个小项目,并且是Scrapy的新成员。 当我跑我的蜘蛛,它显示在我的管道异常错误,说:Pipeline.py显示异常
item['Number'][0], exceptions.IndexError: list index out of range
我管线档案:
import sys
from scrapy.utils.python import unicode_to_str
import MySQLdb
from project2.settings import MYSQL
# the Pipeline settings.
class MySQLStorePipeline(object):
def __init__(self):
db=MySQLdb.connect(user='root', passwd='', db='project2', host='127.0.0.1', charset = "utf8", use_unicode = True)
self.c=db.cursor()
def process_item(self, item, spider):
try:
self.c.execute("""INSERT INTO crawlerapp_directory (Catogory, Bussiness_name, Description, Number, Web_url)
VALUES (%s, %s, %s, %s, %s)""",
(item['Catogory'][0],
item['Bussiness_name'][0],
item['Description'][0],
item['Number'][0],
item['Web_url'][0]))
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit (1)
return item
我的蜘蛛爬行的罚款,但它表示对上述异常错误和也不会将抓取的数据保存到MySQL DB中。
请指导我解决问题。
数量IM尝试存储刮下数据 – user2631770
的电话号码以及ü说,它可能是空的,我试图运行我的蜘蛛没有属性数量,蜘蛛运行良好,错误freee,但它没有保存其余的数据,它正在刮。 – user2631770
请指导我将刮取的数据保存到我的数据库..我正在使用MySQL .. – user2631770