如何在python-webkit中设置user-agent

时间:2012-05-28 01:55:45

标签: python webkit

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”的用户代理,我该怎么办?

1 个答案:

答案 0 :(得分:3)

尝试:

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