在Python程序中embedded一个Web浏览器

我如何在Python程序中embedded一个Web浏览器? 它需要在Linux上运行(GTK,Qt都可以),或者跨平台的。

我已经看过embeddedpywebgtk和Qt的WebKit小部件 。 但是这些似乎只有一个渲染引擎。 特别是,我想支持后退/前进和标签浏览。 是这样的事先打包,还是我必须自己实施?

wxWebConnect似乎大概是我想的,但它没有Python绑定。

http://pypi.python.org/pypi/selenium/2.7.0

你可以安装selenium包并运行一个服务器(同一台机器,只是一个不同的进程)与你连接到你的Python代码的服务器:

java -jar selenium-server-standalone-2.7.0.jar 

然后:

 from selenium import webdriver from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.common.keys import Keys import time browser = webdriver.Firefox() # Get local session of firefox browser.get("http://www.yahoo.com") # Load page assert "Yahoo!" in browser.title elem = browser.find_element_by_name("p") # Find the query box elem.send_keys("seleniumhq" + Keys.RETURN) time.sleep(0.2) # Let the page load, will be added to the API try: browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]") except NoSuchElementException: assert 0, "can't find seleniumhq" browser.close() 

您可以使用subprocess来启动Python代码中的服务器。