# -*- coding: utf-8 -*- from selenium import webdriver import sys from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtWidgets import QMessageBox, QDialog from PyQt5.QtGui import QPixmap, QImage from PyQt5.QtCore import QTimer from PyQt5.QtWidgets import QLabel from PyQt5.QtWidgets import QWidget from arizona import * from selenium.webdriver.firefox.firefox_profile import FirefoxProfile from selenium.webdriver.firefox.firefox_binary import FirefoxBinary import time url_main = 'http://forum.arizona-rp.com/index.php?online/&type=registered' # Адрес форума class MyWidget(QtWidgets.QWidget): def __init__(self): super().__init__() self.ui = Ui_Form() self.ui.setupUi(self) self.setWindowTitle("Флудилка для Аризоны") # События кнопок Авторизации И Регистрации self.ui.floodbutton.clicked.connect(self.Floodbutton) # Поля с ником и паролём self.ui.nick.textChanged[str].connect(self.Nick) self.ui.password.textChanged[str].connect(self.Password) def Floodbutton(self): pass def Nick(self, nick): pass def Password(self, password): pass def parse_fist_list_user(driver, url): url_list_users = [] driver.get(url) # Обход проверки браузера time.sleep(10) # Получаем блок навигации div_PageNav = driver.find_element_by_class_name('PageNav') #Получаем количество страниц count_page = int(div_PageNav.get_attribute('data-last')) #Заполняем список url страниц с пользователями for i in range(1,count_page): url_list_users.append(url_main+'&page='+str(i)) print(url+'&page='+str(i)) return url_list_users def parse_list_users(driver,urls): users_url = [] #Переход по очереди for url in urls: driver.get(url) print('Страница:', url) users = driver.find_elements_by_css_selector('li.memberListItem') for user in users: users_url.append(user.find_element_by_tag_name('a').get_attribute('href')) return users_url # Логинимся def login(driver): logbutton = driver.find_element_by_id('loginBarHandle') logbutton.click() time.sleep(3) loginarea = driver.find_element_by_id('LoginControl') loginarea.send_keys('BNTZ') passwordarea = driver.find_element_by_id('ctrl_password') passwordarea.send_keys('max777') buttonlog_xpath = '//input[@type="submit" and @value="Вход"]' buttonlog = driver.find_element_by_xpath(buttonlog_xpath) buttonlog.click() # Гоняем по аккаунтам и спамим def check_users(driver): usercount = 0 for x in users: driver.get(x) rang = driver.find_element_by_class_name('userBanners') # Проверка на группу if rang.text == "Пользователь": message = driver.find_element_by_name('message') message.send_keys('https://vk.com/samp_portland') NEXT_BUTTON_XPATH = '//input[@type="submit" and @value="Отправить"]' button = driver.find_element_by_xpath(NEXT_BUTTON_XPATH) button.click() usercount += 1 time.sleep(30) print(usercount) else: print('-') def init_driver(): binary = FirefoxBinary("C:\\Users\\Tom\\AppData\\Local\\Mozilla Firefox\\firefox.exe") profile = FirefoxProfile() # если запускаетесь с дефолтным, то можно пропустить driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary, executable_path="C:\\Users\\Tom\\Desktop\\spammer\\geckodriver.exe") return driver if __name__ == "__main__": start = time.time() driver = init_driver() url_list_users = parse_fist_list_user(driver, url_main) users = parse_list_users(driver, url_list_users) for user in users: print(user) print('Количество пользователей онлайн:',str(len(users))) print('Время парсинга:',time.time()-start) login = login(driver) check = check_users(driver) # DEBUG def log_uncaught_exceptions(ex_cls, ex, tb): text = '{}: {}:\n'.format(ex_cls.__name__, ex) import traceback text += ''.join(traceback.format_tb(tb)) print(text) sys.exit(1) sys.excepthook = log_uncaught_exceptions 

How to make the browser (started to run the rest of the code) opened after clicking on the button (Activating the Floodbutton function)

    1 answer 1

    In the same directory, you can create a file with a code in which there is a function in which the browser is opened, its operation, and so on. And in the function that you assigned to clicking on the button enter <file name without extension>. <Name of the desired function from the created file> () At the beginning of your file, import the created file

    That is, to create an example.py file with the func function, which starts the necessary process, and in the function that is executed when you click on the button in the source file, set example.func (). And first of all import the necessary file - import example As a result, the function associated to press a button, it will execute the code located in the example.py file. It is also necessary to take into account that until the code from the file is executed? the work of the main program will be suspended, any graphical interface will hang there until the end of the example.py execution. This can be solved with the help of multithreading - read about the threading library.

    The proposed method may not be very, but you can try to implement it.

    • Unfortunately, this answer did not fit - Maxim Khalin
    • Why? You can also put the necessary part of the code into the function and call it when necessary. And why did not it fit? Maybe I can somehow help - fedotsoldier September