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()
一切正常。