- さくらVPS
- CentOS 6.2
- Python 2.6.6
- MySQL 5.1.61
- MySQL for Python 1.2.4
- MySQL for Pythonのインストール
# wget http://sourceforge.net/projects/mysql-python/files/latest/download # tar xvf MySQL-python-1.2.4b4.tar.gz # python setup.py build # python setup.py installサンプルプログラム。
myMySQLforPython.py
!/usr/bin/env python # coding: utf-8 import MySQLdb con = MySQLdb.connect(db='nutch', host='localhost', user='nutch', passwd='password') cur = con.cursor() q = 'SELECT id, title FROM webpage LIMIT 10' cur.execute(q) rows = cur.fetchall() for row in rows: print "%s ( %s )" % (row[1], row[0]) cur.close() con.close()実行結果。
テスト用テーブルとしてこちらで作成したクロールデータデータベースのものを利用します。
# python myMySQLforPython.py Welcome to Apache Nutch ( org.apache.nutch:http/ ) About Apache Nutch ( org.apache.nutch:http/about.html ) None ( org.apache.nutch:http/about.pdf ) All Classes (apache-nutch 1.6 API) ( org.apache.nutch:http/apidocs-1.6/allclasses-frame.html ) apache-nutch 1.6 API ( org.apache.nutch:http/apidocs-1.6/index.html ) None ( org.apache.nutch:http/apidocs-1.6/org/apache/nutch/analysis/lang/HTMLLanguageParser.html ) None ( org.apache.nutch:http/apidocs-1.6/org/apache/nutch/analysis/lang/LanguageIndexingFilter.html ) None ( org.apache.nutch:http/apidocs-1.6/org/apache/nutch/analysis/lang/package-frame.html ) None ( org.apache.nutch:http/apidocs-1.6/org/apache/nutch/collection/CollectionManager.html ) None ( org.apache.nutch:http/apidocs-1.6/org/apache/nutch/collection/package-frame.html )
0 件のコメント:
コメントを投稿