更改 pyWebkitGTK 中的用户代理和标头?
我已阅读有关制作自己的数据处理程序的建议,例如:(
web_view.connect('resource-request-starting', resource_cb)
def resource_cb(view, frame, resource, request, response):
print request.get_uri()
#get data using urllib with different user-agent...
request.set_uri('data:....')
来自 http:// /code.google.com/p/pywebkitgtk/wiki/HowDoI)
将允许您使用自定义标头/用户代理进行下载。但是,有时如果 set_uri 给出的字符串为空字符,它会抱怨,或者会给出类似“** Message: console message: (http://url) @linenumber: SECURITY_ERR: DOM Exception 18: An attempts was旨在突破用户代理的安全策略。”
有没有更好的方法为 pygtk 代码设置浏览器用户代理? 这表示您可以使用添加/删除/替换标头SoupMessage,但是缺少该文档......
I've read the suggestions for making your own data handler, for example:
web_view.connect('resource-request-starting', resource_cb)
def resource_cb(view, frame, resource, request, response):
print request.get_uri()
#get data using urllib with different user-agent...
request.set_uri('data:....')
(from http://code.google.com/p/pywebkitgtk/wiki/HowDoI)
will let you download using custom header/useragent. However, sometimes it will complain if set_uri is given string with null-char, or it will give an error like "** Message: console message: (http://url) @linenumber: SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent."
Is there a better way to set a browser useragent for pygtk code? This says you can add/remove/replace headers using SoupMessage, however that documentation is missing...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此代码设置一个特殊的用户代理:
http://nullege.com/codes/show/src%40p%40r%40PrisPy-HEAD%40PrisPy.py/33/webkit.WebView/python
webkit.WebSettings() 允许用户代理切换和一些其他设置,但似乎没有添加其他标头的选项。
This code sets a special user-agent:
http://nullege.com/codes/show/src%40p%40r%40PrisPy-HEAD%40PrisPy.py/33/webkit.WebView/python
webkit.WebSettings() allows user-agent switching, and a few other settings, but it seems it doesn't have the option to add other headers.