简体   繁体   English

PyQt4 字符编码:“ascii”编解码器无法编码字符

[英]PyQt4 character encoding: 'ascii' codec can't encode character

Trying to use this following script to load a page so that I can access the page with javascript executed.尝试使用以下脚本加载页面,以便我可以访问执行 javascript 的页面。 I would like to log in and look at the resultant page (https://www.thomsononeim.com/v-hom.asp), also with Javascript executed.我想登录并查看结果页面 (https://www.thomsononeim.com/v-hom.asp),同时执行了 Javascript。 In Python 2.7, I get this error:在 Python 2.7 中,我收到此错误:

Traceback (most recent call last):回溯(最近一次通话最后):
File "C:/Python27/Sample Programs/Stupid Test.py", line 22, in print html UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in position 8273: ordinal not in range(128)文件“C:/Python27/Sample Programs/Stupid Test.py”,第 22 行,打印 html UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in position 8273: ordinal in range (128)

Here's the code:这是代码:

from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtWebKit import *


class Render(QWebPage):
    def __init__(self, url):
        self.app = QApplication(sys.argv)
        QWebPage.__init__(self)
        self.loadFinished.connect(self._loadFinished)
        self.mainFrame().load(QUrl(url))
        self.app.exec_()

    def _loadFinished(self, result):
        self.frame = self.mainFrame()
        self.app.quit()

url = 'https://www.thomsononeim.com/s-log_in.asp'
r = Render(url)
html = r.frame.toHtml()
print(html)

This should work:这应该有效:

print(html.toUtf8())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASCII编解码器无法编码字符 - Ascii codec can't encode character python'ascii'编解码器无法编码字符 - python 'ascii' codec can't encode character ASCII编解码器无法编码字符 - ascii codec can't encode character UnicodeEncodeError:'ascii'编解码器不能编码字符[...] - UnicodeEncodeError: 'ascii' codec can't encode character […] 'ascii'编解码器无法编码字符错误 - 'ascii' codec can't encode character error 编码给出''ascii'编解码器不能编码字符...序数不在范围内(128)“ - Encoding gives “'ascii' codec can't encode character … ordinal not in range(128)” Python中的编码问题-使用UTF-8时,“ ascii”编解码器无法编码字符“ \\ xe3” - Encoding problems in Python - 'ascii' codec can't encode character '\xe3' when using UTF-8 ASCII 编解码器不能编码字符,只能连接 str - ASCII codec can't encode character and can only concat str 收到UnicodeEncodeError的Python脚本:“ ascii”编解码器无法编码字符 - Python script receiving a UnicodeEncodeError: 'ascii' codec can't encode character UnicodeEncodeError: 'ascii' 编解码器无法在打印功能中编码字符 - UnicodeEncodeError: 'ascii' codec can't encode character in print function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM