對於抓取數據量,鏈接數不是很大的情況下,可以選sqlite作爲存儲數據庫。sqlite輕巧,操作方便,快速。不像mysql那樣龐大。
centos下python2.7 scrapy0.16 ,默認情況下,沒有sqlite模塊,我們要自己安裝。
用easy_install 裝,安裝完後,import,出錯了!,如下
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/python2.7.4/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/usr/local/python2.7.4/lib/python2.7/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
網上搜到解決方案是:重裝python,重新編譯,好吧,照做就是了,可編譯python過程又出現問題了。。,如下:
Python build finished, but the necessary bits to build these modules were not found:
_tkinter bsddb185 sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
Failed to build these modules:
_sqlite3
再到網上找解決方案:
在./Modules/_sqlite/connection.c 文件中加入紅色部分
#include "cache.h"
#include "module.h"
#include "connection.h"
#include "statement.h"
#include "cursor.h"
#include "prepare_protocol.h"
#include "util.h"
#include "sqlitecompat.h"
#include "pythread.h"
#define ACTION_FINALIZE 1
#define ACTION_RESET 2
#if SQLITE_VERSION_NUMBER >= 3003008
#ifndef SQLITE_OMIT_LOAD_EXTENSION
#define HAVE_LOAD_EXTENSION
#endif
#endif
#ifdef SQLITE_INT64_TYPE
typedef SQLITE_INT64_TYPE sqlite_int64;
typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
#elif defined(_MSC_VER) || defined(__BORLANDC__)
typedef __int64 sqlite_int64;
typedef unsigned __int64 sqlite_uint64;
#else
typedef long long int sqlite_int64;
typedef unsigned long long int sqlite_uint64;
#endif
typedef sqlite_int64 sqlite3_int64;
typedef sqlite_uint64 sqlite3_uint64;
重新make,還是failed
網上又找到方法,如下:
安裝sqlite3
下載 sqlite (如sqlite-amalgamation-3.6.20.tar.gz)
下載地址:http://www.sqlite.org/sqlite-amalgamation-3.6.20.tar.gz
安裝sqlite, 如果要安裝到用戶指定目錄,可以: $./configure --prefix=/your/path/(我用的/usr/local)
安裝sqlite成功,import一下,還是不行,於是又到Python2.7安裝目錄下make,這次 竟然make通過了,沒報failed,然後make install。
等一會兒,python裝完了,再import sqlite3,成功了,額滴個神啊,終於搞定了。。。。
參考網站:
1.http://gcxieblog.blog.163.com/blog/static/56837839200911105418606/
2.http://blog.csdn.net/chenggong2dm/article/details/7692826