2012-05-28 49 views
2
import webkit 
import gtk 
import jswebkit 

webview = webkit.WebView() 
webview.connect('load-finished', lambda v, f: gtk.main_quit()) 
# How can I set user-agent ? 
webview.load_uri('http://localhost/tech/test.html') 
gtk.main() 
js = jswebkit.JSContext(webview.get_main_frame().get_global_context()) 
renderedBody = str(js.EvaluateScript('document.body.innerHTML')) 
print renderedBody 

我想爲webkit.WebView設置像「iPad」或其他的用戶代理,我該怎麼辦?如何在python-webkit中設置用戶代理

回答

3

嘗試:

settings = webkit.WebSettings() 
    settings.set_property('user-agent', 'iPad') 
    webview.set_settings(settings) 
相關問題