如何使用python和qtwebengine登录Gmail?

2024-03-29 02:01:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个包含基于qtwebengine的浏览器的GUI,我想登录到Gmail或我的任何其他网站浏览器.can我用selenium还是Webbot?我知道qtwebengine使用chrome。但我不知道如何与selenium或webbot一起使用。 这是我的示例代码:

class e_browser(QMainWindow,Ui_Form_ELearning_browser):

def __init__(self, parent=None):
    super(e_browser, self).__init__(parent)
    self.ui_main = Ui_Form_ELearning_browser()
    self.ui_main.setupUi(self)

    self.web = QWebEngineView(self)
    self.web.setGeometry(QtCore.QRect(10, 230, 1041, 1671))
    self.ui_main.pushButton.clicked.connect(self.close)

    self.open_browser()

def open_browser(self):
    self.web.load(QUrl("https://www.google.com"))

    # browser_url = '/mnt/testbrowser'
    # chromeOptions = webdriver.ChromeOptions()
    # chromeOptions.binary_location = browser_url
    #
    # driver = Browser()
    # driver.get('https://www.google.com')

    web2 = Browser()
    web2.go_to('google.com')
    web2.click('Sign in')
    web2.type('mymail@gmail.com', into='Email')
    web2.click('NEXT', tag='span')
    web2.type('mypassword', into='Password', id='passwordFieldId')  # specific selection
    web2.click('NEXT', tag='span')
    self.web.show()

如果名称==“main”: 导入子流程

# subprocess.run(["./Scripts/portrait.sh"])
app = QtWidgets.QApplication(sys.argv)
Forms = e_browser()
Forms.show()
sys.exit(app.exec_())

Tags: selfbrowserformcomwebuimainselenium