Я знаю, что это будет простое исправление, но я не могу понять, почему я не могу заставить Send_Keys набрать текст QLabel в pyqt5
Это то, что у меня так далеко:
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout, QPushButton, QLabel, QLineEdit, QGridLayout, QGroupBox, QDialog
from PyQt5.QtCore import pyqtSlot
from requests import get
from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from requests import get
import time
class Window(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle("Project PiBu!!")
self.game_name = QLabel("Game Name:", self)
self.game_line_edit = QLineEdit(self)
self.search_button = QPushButton("Search", self)
self.search_button.clicked.connect(self.on_click)
self.game = QLabel(self)
self.results = QLabel("Results For:", self)
self.meta_critic_label = QLabel("Metacritic Score:", self)
self.user_score_label = QLabel("User Score:", self)
self.meta_critic_score = ""
self.user_score_score = ""
self.createGridLayout()
self.windowLayout = QVBoxLayout()
self.windowLayout.addWidget(self.horizontalGroupBox)
self.setLayout(self.windowLayout)
self.show()
def createGridLayout(self):
self.horizontalGroupBox = QGroupBox()
self.layout = QGridLayout()
self.layout.setColumnStretch(1, 3)
self.layout.setColumnStretch(2, 3)
self.layout.setColumnStretch(3, 3)
self.layout.setColumnStretch(4, 3)
self.layout.addWidget(self.game_name, 0, 0)
self.layout.addWidget(self.game_line_edit, 0, 1)
self.layout.addWidget(self.search_button, 0, 2)
self.layout.addWidget(self.results, 1, 0)
self.layout.addWidget(self.game, 2, 0)
self.layout.addWidget(self.meta_critic_label, 1, 1)
self.layout.addWidget(self.user_score_label, 1, 2)
self.horizontalGroupBox.setLayout(self.layout)
@pyqtSlot()
def on_click(self):
self.game.setText(self.game_line_edit.text())
# options = Options()
# options.add_argument("--headless") # Runs Chrome in headless mode.
# options.add_argument('--no-sandbox') # # Bypass OS security model
# options.add_argument('start-maximized')
# options.add_argument('disable-infobars')
# options.add_argument("--disable-extensions")
# driver = webdriver.Chrome(chrome_options=options, executable_path='/home/littlejiver/Downloads/chromedriver')
self.driver = webdriver.Chrome()
self.driver.get("https://www.metacritic.com/game")
print("Headless Chrome Initialized on Linux OS")
self.search_element = self.driver.find_element_by_name("search_term")
self.search_element.clear()
self.search_element.send_keys(self.game)
# self.game_line_edit.setText("")
if __name__ == '__main__':
app = QApplication(sys.argv)
win = Window()
sys.exit(app.exec_())
Я получаю эту ошибку:
TypeError: object of type 'QLabel' has no len()
Я не могу понять, как захватить текст, введенный в "QLineEdit", который записан в "QLabel", в переменную, которая может быть "прочитана"send_keys
Надеюсь, это имеет смысл:)
Спасибо!