Python 中的网络浏览器
问题描述:
我尝试打开带有俄罗斯符号的页面.
I trying open page with Russian symbols.
webbrowser.open('https://www.google.com/?q=привет')
但我在浏览器中有这个:https://www.google.com/?q=一个>??????
But I have this in browser: https://www.google.com/?q=??????
答
使用 unicode 字符串.
Use a unicode string.
webbrowser.open(u'https://www.google.com/?q=привет')
您可能还想对源文件使用 UTF-8 编码,因此请确保您的编辑器实际保存为 UTF-8 并将其添加到程序顶部
You'll probably also want to use UTF-8 encoding for your source file, so make sure your editor actually saves in UTF-8 and add this to the top of the program
# -*- coding: utf-8 -*-