Trying to use this following script to load a page so that I can access the page with javascript executed. I would like to log in and look at the resultant page (https://www.thomsononeim.com/v-hom.asp), also with Javascript executed. In Python 2.7, I get this error:
Traceback (most recent call last):
File "C:/Python27/Sample Programs/Stupid Test.py", line 22, in print html UnicodeEncodeError: 'ascii' codec can't encode char开发者_JS百科acter u'\xa9' in position 8273: ordinal not 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())
精彩评论