Forums

question about python and playwright.

Hello, someone can help me please? I doing now a basic bot with python and playwright, but the bot in execution, does login and close, but I want it to continue for the next page

example:

the bot does login in "https://www.instagram.com/accounts/login/" and close

I want it to does login and continue to "https://www.instagram.com"

if someone help me, I thanks to you.

PS: The code contains PyQt5.

CODE:

from PyQt5 import QtCore, QtGui, QtWidgets import time from playwright.sync_api import sync_playwright

class Ui_InstaBOT(object):

def logar(self):
    email = self.login.text()
    passw = self.senha.text()
    with sync_playwright() as p:
        browser = p.chromium.launch(headless=False)
        page = browser.new_page()
        page.goto("https://www.instagram.com/accounts/login/")
        time.sleep(2)
        page.click('input[name="username"]')
        page.fill('input[name="username"]', email)
        page.click('input[name="password"]')
        page.fill('input[name="password"]', passw)
        page.press('input[name="password"]', passw)
        page.wait_for_selector("https://www.instagram.com/")
        page.goto('https://www.instagram.com/')
        page.click('input[class="XTCLo x3qfX"]')
        page.fill('input[class="XTCLo x3qfX"]')
        time.sleep(3)
        browser.close()




def setupUi(self, InstaBOT):
    InstaBOT.setObjectName("InstaBOT")
    InstaBOT.resize(400, 500)
    icon = QtGui.QIcon()
    icon.addPixmap(QtGui.QPixmap("imagens/icone.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
    InstaBOT.setWindowIcon(icon)
    self.InstaBot = QtWidgets.QWidget(InstaBOT)
    self.InstaBot.setMinimumSize(QtCore.QSize(400, 500))
    self.InstaBot.setMaximumSize(QtCore.QSize(400, 500))
    self.InstaBot.setObjectName("InstaBot")
    self.frame_2 = QtWidgets.QFrame(self.InstaBot)
    self.frame_2.setGeometry(QtCore.QRect(0, 0, 411, 501))
    self.frame_2.setStyleSheet("background-color: rgb(89, 89, 89);")
    self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
    self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
    self.frame_2.setObjectName("frame_2")
    self.iniciar = QtWidgets.QPushButton(self.frame_2)
    self.iniciar.setGeometry(QtCore.QRect(120, 310, 151, 41))
    self.iniciar.setFocusPolicy(QtCore.Qt.ClickFocus)
    self.iniciar.setStyleSheet("QPushButton{\n"

"background-color: rgb(45, 45, 45);\n" "border: 3px solid black;\n" "\n" "border-radius: 8px;\n" "\n" "font: 8pt \"MV Boli\";\n" "}\n" "\n" "QPushButton::hover{\n" "background-color: rgb(157, 25, 25);\n" "}\n" "\n" "\n" "") self.iniciar.setObjectName("iniciar") self.frame = QtWidgets.QFrame(self.frame_2) self.frame.setGeometry(QtCore.QRect(-50, -40, 421, 211)) self.frame.setStyleSheet("background-image: url(:/fundo/imagens/fundo.png);\n" "border: 4px;") self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel) self.frame.setFrameShadow(QtWidgets.QFrame.Raised) self.frame.setObjectName("frame") self.login = QtWidgets.QLineEdit(self.frame_2) self.login.setGeometry(QtCore.QRect(130, 220, 131, 31)) self.login.setStyleSheet("QLineEdit{\n" "background-color: rgb(18, 18, 18);\n" "color: rgb(117, 117, 117);\n" "border: 4px solid;\n" "border-radius: 10px;\n" "}\n" "\n" "QLineEdit::after{\n" "background-color: rgb(18, 18, 18);\n" "color: rgb(255, 0, 0);\n" "border: 4px solid;\n" "border-color: rgb(255, 0, 0);\n" "border-radius: 10px;\n" "}\n" "\n" "") self.login.setText("") self.login.setObjectName("login") self.senha = QtWidgets.QLineEdit(self.frame_2) self.senha.setGeometry(QtCore.QRect(130, 260, 131, 31)) self.senha.setStyleSheet("QLineEdit{\n" "background-color: rgb(18, 18, 18);\n" "color: rgb(117, 117, 117);\n" "border: 4px solid;\n" "border-radius: 10px;\n" "}") self.senha.setText("") self.senha.setObjectName("senha") InstaBOT.setCentralWidget(self.InstaBot)

    self.iniciar.clicked.connect(self.logar)

    self.retranslateUi(InstaBOT)
    QtCore.QMetaObject.connectSlotsByName(InstaBOT)

def retranslateUi(self, InstaBOT):
    _translate = QtCore.QCoreApplication.translate
    InstaBOT.setWindowTitle(_translate("InstaBOT", "InstaBOT"))
    self.iniciar.setText(_translate("InstaBOT", "INICIAR"))
    self.login.setPlaceholderText(_translate("InstaBOT", "Login"))
    self.senha.setPlaceholderText(_translate("InstaBOT", "Senha"))

import fundo

if name == "main": import sys app = QtWidgets.QApplication(sys.argv) InstaBOT = QtWidgets.QMainWindow() ui = Ui_InstaBOT() ui.setupUi(InstaBOT) InstaBOT.show() sys.exit(app.exec_()) from playwright.sync_api import sync_playwright

class Ui_InstaBOT(object):

def logar(self):
    email = self.login.text()
    passw = self.senha.text()
    with sync_playwright() as p:
        browser = p.chromium.launch(headless=False)
        page = browser.new_page()
        page.goto("https://www.instagram.com/accounts/login/")
        time.sleep(2)
        page.click('input[name="username"]')
        page.fill('input[name="username"]', email)
        page.click('input[name="password"]')
        page.fill('input[name="password"]', passw)
        page.press('input[name="password"]', passw)
        page.wait_for_selector("https://www.instagram.com/")
        page.goto('https://www.instagram.com/')
        page.click('input[class="XTCLo x3qfX"]')
        page.fill('input[class="XTCLo x3qfX"]')
        time.sleep(3)
        browser.close()




def setupUi(self, InstaBOT):
    InstaBOT.setObjectName("InstaBOT")
    InstaBOT.resize(400, 500)
    icon = QtGui.QIcon()
    icon.addPixmap(QtGui.QPixmap("imagens/icone.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
    InstaBOT.setWindowIcon(icon)
    self.InstaBot = QtWidgets.QWidget(InstaBOT)
    self.InstaBot.setMinimumSize(QtCore.QSize(400, 500))
    self.InstaBot.setMaximumSize(QtCore.QSize(400, 500))
    self.InstaBot.setObjectName("InstaBot")
    self.frame_2 = QtWidgets.QFrame(self.InstaBot)
    self.frame_2.setGeometry(QtCore.QRect(0, 0, 411, 501))
    self.frame_2.setStyleSheet("background-color: rgb(89, 89, 89);")
    self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
    self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
    self.frame_2.setObjectName("frame_2")
    self.iniciar = QtWidgets.QPushButton(self.frame_2)
    self.iniciar.setGeometry(QtCore.QRect(120, 310, 151, 41))
    self.iniciar.setFocusPolicy(QtCore.Qt.ClickFocus)
    self.iniciar.setStyleSheet("QPushButton{\n"

"background-color: rgb(45, 45, 45);\n" "border: 3px solid black;\n" "\n" "border-radius: 8px;\n" "\n" "font: 8pt \"MV Boli\";\n" "}\n" "\n" "QPushButton::hover{\n" "background-color: rgb(157, 25, 25);\n" "}\n" "\n" "\n" "") self.iniciar.setObjectName("iniciar") self.frame = QtWidgets.QFrame(self.frame_2) self.frame.setGeometry(QtCore.QRect(-50, -40, 421, 211)) self.frame.setStyleSheet("background-image: url(:/fundo/imagens/fundo.png);\n" "border: 4px;") self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel) self.frame.setFrameShadow(QtWidgets.QFrame.Raised) self.frame.setObjectName("frame") self.login = QtWidgets.QLineEdit(self.frame_2) self.login.setGeometry(QtCore.QRect(130, 220, 131, 31)) self.login.setStyleSheet("QLineEdit{\n" "background-color: rgb(18, 18, 18);\n" "color: rgb(117, 117, 117);\n" "border: 4px solid;\n" "border-radius: 10px;\n" "}\n" "\n" "QLineEdit::after{\n" "background-color: rgb(18, 18, 18);\n" "color: rgb(255, 0, 0);\n" "border: 4px solid;\n" "border-color: rgb(255, 0, 0);\n" "border-radius: 10px;\n" "}\n" "\n" "") self.login.setText("") self.login.setObjectName("login") self.senha = QtWidgets.QLineEdit(self.frame_2) self.senha.setGeometry(QtCore.QRect(130, 260, 131, 31)) self.senha.setStyleSheet("QLineEdit{\n" "background-color: rgb(18, 18, 18);\n" "color: rgb(117, 117, 117);\n" "border: 4px solid;\n" "border-radius: 10px;\n" "}") self.senha.setText("") self.senha.setObjectName("senha") InstaBOT.setCentralWidget(self.InstaBot)

    self.iniciar.clicked.connect(self.logar)

    self.retranslateUi(InstaBOT)
    QtCore.QMetaObject.connectSlotsByName(InstaBOT)

def retranslateUi(self, InstaBOT):
    _translate = QtCore.QCoreApplication.translate
    InstaBOT.setWindowTitle(_translate("InstaBOT", "InstaBOT"))
    self.iniciar.setText(_translate("InstaBOT", "INICIAR"))
    self.login.setPlaceholderText(_translate("InstaBOT", "Login"))
    self.senha.setPlaceholderText(_translate("InstaBOT", "Senha"))

import fundo

if name == "main": import sys app = QtWidgets.QApplication(sys.argv) InstaBOT = QtWidgets.QMainWindow() ui = Ui_InstaBOT() ui.setupUi(InstaBOT) InstaBOT.show() sys.exit(app.exec_())

These forums are for help with PythonAnywhere, but perhaps one of our users can help you.