文章标签 ‘python’

转载时请标明文章原始出处和作者信息, 作者: lostsnow.http://www.lsproc.com/blog/python_spider/

#coding=utf-8

import sys
import urllib2
import gzip
import StringIO

# 页面url
url = "http://china.toocle.com/company/show/pdetail--1000436--10532651.html"
# 页面编码
page_encode = "gbk"

request = urllib2.Request(url)
request.add_header("Accept-encoding", "gzip")
usock = urllib2.urlopen(request)
page = usock.read()
# 处理gzip过的页面
if usock.headers.get('content-encoding', None) == 'gzip':
page = gzip.GzipFile(fileobj=StringIO.StringIO(page)).read()

# 转unicode(gbk/utf8)
if not isinstance(page, unicode):
page = unicode(page, page_encode)

print(page)

-- EOF --

2010年2月1日14:34 | 没有评论
标签: ,

转载时请标明文章原始出处和作者信息, 作者: lostsnow.http://www.lsproc.com/blog/python_pil/
pil站点: http://www.pythonware.com/products/pil/index.htm
pil下载: http://effbot.org/downloads/Imaging-1.1.6.tar.gz
pil文档: http://www.pythonware.com/library/pil/handbook/index.htm
  
[安装]
$ tar zxvf Imaging-1.1.6.tar.gz
$ cd Imaging-1.1.6
$ python setup.py build_ext -i
$ python selftest.py
$ python setup.py install
安装完毕后,可在python安装目录下的site-packages找到PIL安装目录。
-- EOF --

2008年11月10日16:03 | 没有评论
标签: ,

转载时请标明文章原始出处和作者信息, 作者: lostsnow.http://www.lsproc.com/blog/configure_python_and_django_on_dreamhost/
1. 升级python到2.5.2:
用Putty登录到DreamHost的Shell控制台执行如下的命令:

mkdir opt
cd opt
mkdir packages
cd packages
wget http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tgz
tar -xzvf Python-2.5.2.tgz
cd Python-2.5.2
./configure -prefix=$HOME/opt
make
make install

python 2.5已经安装好了。把python 2.5设置为默认版本:

vim ~/.bash_profile

然后,在~/.bash_profile里加入一条:

export PATH=$HOME/opt/bin/:$PATH

重新载入配置文件:

source ~/.bash_profile

检验一下是否成功:

$python -V
Python 2.5.2

2. 安装python-Mysql

cd ~/opt/packages
wget http://internap.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.2.tar.gz
tar xvzf MySQL-python-1.2.2.tar.gz
cd MySQL-python-1.2.2
python setup.py install

3. 安装django

cd ~/opt/packages
wget http://www.djangoproject.com/download/1.0/tarball/
tar -xzvf Django-1.0.tar.gz
cd Django-1.0
python setup.py install

在python交互环境下查看django的版本,以测试安装配置的准确性。

$python
>>>import django
>>>django.VERSION
(1, 0, 'final')

4. 创建Django项目

mkdir ~/django_projects
cd ~/django_projects
django-admin.py startproject myproject
chmod 600 myproject/settings.py

vim myproject/settings.py :

DATABASE_ENGINE = 'mysql' [...]

2008年11月5日21:56 | 5 条评论