如何用Python开发一个简单的Webkit浏览器

Python022

如何用Python开发一个简单的Webkit浏览器,第1张

你好,

1,基于IE内核的浏览器直接用VB编写即可。引用WEBbrowser就可以了。复杂的操作可能要实现某些接口,比如拦截下载事件等。这部分用VB比较复杂,用Delphi比较合适。

2,webkit有现成封装的ActiveX,可以直接被VB调用。

但自己编写webkit内核的浏览器比较困难。

下载源码

安装

mkdir build

cd build

../autogen.sh

出现错误提示:

automake: cannot open <gtk-doc.make: No such file or directory

sudo apt-get install gtk-doc-tools

继续第二步

../autogen.sh

出现错误:

configure: error: You need the 'flex' lexer generator to compile WebKit

google 一下关于 flex的资料

Flex 是一个高效、免费的开源框架,可用于构建具有表现力的 Web 应用程序,这些应用程序利用 Adobe Flash Player和 Adobe AIR, 运行时跨浏览器、桌面和操作系统实现一致的部署。虽然只能使用 Flex 框架构建 Flex 应用程序,但Adobe Flash Builder™(之前称为 Adobe Flex Builder™)软件可以通过智能编码、交互式遍历调试以及可视设计用户界面布局等功能加快开发。

网址: http://www.adobe.com/devnet/flex/flex-sdk-download-all.html

下载之后解压缩,发现不是我这里想要的source

百度了一下 flex ,在第一页的最下面一个网页,标题: flex: The Fast Lexical Analyzer

打开 http://flex.sourceforge.net/ 之后,看了一下介绍:

Flex is a tool for generating scanners. A scanner, sometimes called a tokenizer, is a program which recognizes lexical patterns in text. The flex program reads user-specified input files, or its standard input if no file names are given, for a description of a scanner to generate. The description is in the form of pairs of regular expressions and C code, called rules. Flex generates a C source file named, "lex.yy.c", which defines the function yylex(). The file "lex.yy.c" can be compiled and linked to produce an executable. When the executable is run, it analyzes its input for occurrences of text matching the regular expressions for each rule. Whenever it finds a match, it executes the corresponding C code.

下载之后,安装成功,执行 flex --version ,显示:flex 2.5.37,安装成功.

继续第二步

../autogen.sh

出现错误:configure: error: You need the 'gperf' hash function generator to compile WebKit

gperf网址:http://www.gnu.org/software/gperf/

安装 gperf:

wget http://ftp.gnu.org/pub/gnu/gperf/gperf-3.0.4.tar.gz

tar zxvf gperf-3.0.4.tar.gz

cd gperf-3.0.4/

./configure

make

make install

继续第二步

../autogen.sh

出现错误:configure: error: JPEG library (libjpeg) not found

IJG is an informal group that writes and distributes a widely used free library for JPEG image compression. The first version was released on 7-Oct-1991.

安装 jpeg library:

到http://www.ijg.org/找到下载源码的链接

wget http://www.ijg.org/files/jpegsrc.v8d.tar.gz

cd jpeg-8d/

./configure

make

sudo make install

安装成功

继续第二步

../autogen.sh

出现错误:configure: error: PNG library (libpng) not found

libpng: http://www.libpng.org/pub/png/libpng.html

安装:

wget http://downloads.sourceforge.net/project/libpng/libpng15/1.5.13/libpng-1.5.13.tar.xz

tar xvf libpng-1.5.13.tar.xz

cd libpng-1.5.13

./configure

make

sudo make install

安装成功

继续第二步

../autogen.sh

libpng的错误仍然出现: configure: error: PNG library (libpng) not found

观察了一下编绎的配制过程:

checking for libpng... no

checking for libpng14... no

checking for libpng12... no

checking for png_read_info in -lpng... no

configure: error: PNG library (libpng) not found

checking的是libpng1.4版本,而刚才安装的是libpng1.5版本

抓取js动态生成的内容的页面有两种基本的解决方案

1用dryscrape库动态抓取页面

js脚本是通过浏览器来执行并返回信息的,所以,抓取js执行后的页面,一个最直接的方式就是用python模拟浏览器的行为。WebKit 是一个开源的浏览器引擎,python提供了许多库可以调用这个引擎,dryscrape便是其中之一,它调用webkit引擎来处理包含js等的网页!

2 selenium web测试框架

selenium是一个web测试框架,它允许调用本地的浏览器引擎发送网页请求,所以,它同样可以实现抓取页面的要求。