PyQt中的evaluateJavaScript不会将我重定向到下一页

时间:2014-09-05 13:34:17

标签: javascript jquery python-3.x pyqt4 qwebview

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
import sys
from time import time, sleep

class Browser(QWebView):

    def __init__(self):
        super(Browser, self).__init__()
        self.page().frameCreated.connect(self.print_load_finished)

    def print_load_finished(self):
        frame = self.page().mainFrame()
        document = frame.documentElement()
        button = document.getElementById("navPromotionBtn")
        button.evaluateJavaScript("this.click()")
        #or frame.documentElement().evaluateJavaScript("document.getElementById('navPromotionBtn').click()")

if __name__=='__main__':


    app = QApplication(sys.argv)
    first = Browser()
    first.show()
    first.load(QUrl('https://www.bet-at-home.com/en/sport/today'))
    sys.exit(app.exec_())

有人可以告诉我为什么这不起作用,当控制台下的一切都很好时(这是最奇怪的)..当我尝试它时document.getElementById("navPromotionBtn").click()一切正常。

0 个答案:

没有答案