我想用PyQt/QWebview來加載一個特定的URL,2)在表單中輸入信息,3)點擊按鈕/鏈接。機械化不起作用,因爲我需要一個實際的瀏覽器。使用PyQt和QWebview填寫表格
這裏是我的代碼:
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
from PyQt4 import QtCore
app = QApplication(sys.argv)
web = QWebView()
web.load(QUrl("https://www.lendingclub.com/account/gotoLogin.action"))
def fillForm():
doc = web.page().mainFrame().documentElement()
user = doc.findFirst("input[id=master_username]")
passwd = doc.findFirst("input[id=master_password]")
user.setAttribute("value", "[email protected]")
passwd.setAttribute("value", "password")
button = doc.findFirst("input[id=master_sign-in-submit]")
button.evaluateJavaScript("click()")
QtCore.QObject.connect(web, QtCore.SIGNAL("loadFinished"), fillForm)
web.show()
sys.exit(app.exec_())
該頁面加載正確,但沒有輸入輸入和形式尚未提交。有任何想法嗎?
setAttribute works – Like