PyQT を使用した Webkit のヘッドレス ブラウザー実装を使用すると、大量の JS コードが含まれていても、各 URL の html コードが自動的に取得されるという印象を受けました。しかし、私はそれを部分的にしか見ていません。Firefox ウィンドウからページを保存したときに得られるページと比較しています。
私は次のコードを使用しています -
class JabbaWebkit(QWebPage):
# 'html' is a class variable
def __init__(self, url, wait, app, parent=None):
super(JabbaWebkit, self).__init__(parent)
JabbaWebkit.html = ''
if wait:
QTimer.singleShot(wait * SEC, app.quit)
else:
self.loadFinished.connect(app.quit)
self.mainFrame().load(QUrl(url))
def save(self):
JabbaWebkit.html = self.mainFrame().toHtml()
def userAgentForUrl(self, url):
return USER_AGENT
def get_page(url, wait=None):
# here is the trick how to call it several times
app = QApplication.instance() # checks if QApplication already exists
if not app: # create QApplication if it doesnt exist
app = QApplication(sys.argv)
#
form = JabbaWebkit(url, wait, app)
app.aboutToQuit.connect(form.save)
app.exec_()
return JabbaWebkit.html
コードに明らかに問題があることを誰かが見ることができますか?
いくつかの URL を介してコードを実行した後、私が遭遇した問題を非常に明確に示すものを見つけました - http://www.chilis.com/EN/Pages/menu.aspx
ご指摘ありがとうございます。