Skip to content

Instantly share code, notes, and snippets.

@bububa
Created November 29, 2011 15:34
Show Gist options
  • Save bububa/1405197 to your computer and use it in GitHub Desktop.
Save bububa/1405197 to your computer and use it in GitHub Desktop.
Python Webkit DOM Bindings
最近研究了下pythonwebkit,于是就想如果可以在python中运行js 还有操作dom 那该多好啊,于是google了一翻,发现了一些比较有用的资料(Python Webkit DOM Bindings),pythonwebkit 的开发版本已经支持dom的操作,不过需要你编译最新的源代码,这样的话你就可以获得一些额外的函数来进行dom的操作.
官方介绍的步骤:
1,git clone git://git.savannah.gnu.org/pythonwebkit.git
// 这个方法是获取pythonwebkit 的源代码,
//如果你已经安装了pythonwebkit可以先卸载掉
2,git checkout -b python_codegen
// checkout python_codegen 分支,请确定你一定要在python_codegen 分支上
//这个是以后你成功的关键 可以通过 git branch 来确定你在哪个分支上
3,git branch
//结果应该是这样的
// master
// * python_codegen
4, compile pythonwebkit
// mkdir build
// cd build
// ../autogen.sh
// ./configure
// make
// make install
5, git clone git://github.com/lkcl/pywebkitgtk.git
//获取pywebkitgtk
6, git checkout -b pythonwebkitgtk_1_1_8
// 这里非常重要,请记住一定要是 pythonwebkitgtk_1_1_8
// 我在这里浪费了很多的时间,it must be pythonwebkitgtk_1_1_8
7, compile pywebkitgtk
// ./autogen.sh, ./configure, make, make install
如果你一路很顺利的话,那祝福你,你真的是比较幸运的,去验证你是不是安装正确 :python -v ; import webkit ,如果没有错的这说明你安装正确了.但是我很不幸,花了三天才弄好.第一个错误出现是我没有获取到正确的pywebktgtk ,请记住一定要确保你用的是pythonwebkitgtk_1_1_8 分支, 第二个错误当我编译完pywebkitgtk 后,import webkit 的时候出现下面的错误
Traceback (most recent call last):
File "
", line 1, in
File "/usr/local/lib/python2.6/dist-packages/webkit/__init__.py",
line 21, in
import webkit
ImportError: /usr/local/lib/python2.6/dist-packages/webkit/webkit.so:
undefinedsymbol: webkit_init_pywebkit
之后去了他们的mail list,发现有一个叫jim 的和我遇到一样的错误,在他的帮助下解决了这个问题,问题的原因是pywebkitgtk 没有找到pythonwebkit 的包的位置
My guess is that pywebkitgtk is not looking in the right place
forthe pythonwebkit shared library.
解决办法就是在编译pywebkitgtk 之前
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
然后重新编译一下pywebkitgtk 就可以了.
最后,谢谢 Luke 和 Jim 的帮忙,国外的一些大牛们很喜欢帮助人.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment