【发布时间】:2015-01-08 20:43:12
【问题描述】:
我正在尝试插入一大组(430 个条目)字典条目,其中一个键值对具有与其关联的薪水,格式为 $xx,xxx,xxx 。我该如何解决这个问题,因为现在它将采用那个值并将其分成 3 列。
编辑:
def process_item(self, item, spider):
if isinstance(item, TeamStats):
for key, value in item.iteritems():
if key == "division":
print(item.get('division', ""))
self.cur.execute("INSERT INTO Divs( division ) VALUES(?)", (item.get('division', ""),))
self.con.commit()
if isinstance(item, Player):
self.cur.execute("INSERT INTO Players(\
player_name, \
salary, \
weight, \
age, \
height, \
position, \
college \
) \
VALUES( ?, ?, ?, ?, ?, ?, ?)", \
( \
item.get('name', ''),
item.get('salary', 0),
item.get('weight', 0),
item.get('age', 0),
item.get('height', ''),
item.get('position', ''),
item.get('college', '')
))
self.con.commit()
return item
我插入管道的对象如下所示:
$600,000 2015-01-08 14:17:59-0500 [nbaStats] 调试:从 http://espn.go.com/nba/team/roster//name/mil/milwaukee-bucks> 抓取 {'年龄':你'21', '大学': u'LSU', '身高': u'6-9', 'name': u"Johnny O'Bryant III", '位置': u'PF', '薪水': u'$600,000', '重量': u'265'} 5,200,000 美元 2015-01-08 14:17:59-0500 [nbaStats] 调试:从 http://espn.go.com/nba/team/roster//name/mil/milwaukee-bucks> 抓取 {'年龄':你'30', '学院': u'\xa0', '身高': u'6-11', '名称': u'Zaza Pachulia', '位置': u'C', '薪水': u'$5,200,000', '重量': u'270'}
【问题讨论】:
-
请贴一些代码。
标签: python mysql sqlite scrapy