Created
October 17, 2018 06:08
-
-
Save sergiks/bbe6a59f23d03438ca6bebc2473e89a4 to your computer and use it in GitHub Desktop.
Python QT web browser webview component example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# src: https://python.su/forum/topic/33143/?page=1#post-181129 | |
import sys | |
from PyQt5 import QtCore, QtWidgets | |
from PyQt5.QtWebEngineWidgets import QWebEngineView | |
class Browser(QWebEngineView): | |
def __init__(self): | |
super().__init__() | |
self.loadFinished.connect(self._auth) | |
self._timer = QtCore.QTimer() | |
self._timer.timeout.connect(self._check_captcha) | |
def _auth(self): | |
page = self.page() | |
page.runJavaScript( | |
'document.querySelector("#index_email").value = "{}"'.format( | |
'12345' | |
) | |
) | |
page.runJavaScript( | |
'document.querySelector("#index_pass").value = {}'.format('12345') | |
) | |
page.runJavaScript( | |
'document.querySelector("#index_login_button").click()' | |
) | |
self._timer.start(1000) | |
def _check_captcha(self): | |
self._timer.stop() | |
self.page().runJavaScript( | |
('document.querySelector("#box_layer > div.popup_box_container > ' | |
'div > div.box_title_wrap > div.box_title").innerHTML'), | |
self._check_captcha_callback | |
) | |
def _check_captcha_callback(self, text): | |
if text == 'Введите код с картинки': | |
print('Нужно ввести капчу') | |
app = QtWidgets.QApplication(sys.argv) | |
b = Browser() | |
b.load(QtCore.QUrl('https://vk.com')) | |
b.show() | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment