python - 如何在 python-webkit 中设置用户代理

标签 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”或其他,我该怎么做?

最佳答案

尝试:

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

关于python - 如何在 python-webkit 中设置用户代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10778595/

相关文章:

python - 使用 interp1d 在数据帧中按行插值

CSS 属性选择器 + 后代在 Webkit 中出现错误?

python - OpenCV在不良图像上使用各种方法绘制轮廓

python-在for循环中将q写为i的函数

jquery - 在 Chrome/WebKit/Safari 中禁用 anchor

html - 如何在所有浏览器的特定 div 中隐藏垂直滚动条

html - Webkit 选取框仅在必要时滚动

css mix-blend-mode 和 masks

python - 如何在 Maya 上检索 cmds.polyExtrude 创建的顶点

python - Flask 更新查询