使用了下java版本的爬虫软件 webmagic,结果发现只能抓静态页面,抓 ajax 数据抓不到。
再尝试用 python, python 有个 webkit 的库,不知道是否可以抓取ajax数据页面。
python 安装 mysql 支持,有两种安装方式:
1. pip install mysql-python
首先需要安装 vc9 for python 的编译器,会遇到很多问题;
参考:http://www.cnblogs.com/fnng/p/4115607.html
2. 直接安装 python mysql 编译好的版本,然后在python命令行使用 import MySQLdb 测试无问题就说明可以用了。
下载链接:http://www.codegood.com/archives/129
python 2.7 默认字符编码是 ascii,在显示中文时会输出 u'\xxx' 类似的字符串,要改为utf-8编码即可显示正常:
方法: 在 C:\Python27\Lib\site-packages 目录下新建 sitecustomize.py 文件,输入如下内容:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#file name: sitecustomize.py
import sys
sys.setdefaultencoding('utf-8')
import sys
sys.setdefaultencoding('utf-8')
然后重新启动 python 命令行:
输入 import sys
sys.getdefaultencoding()
就可以看到utf-8的结果了。