TA的每日心情 | 无聊 4 天前 |
---|
签到天数: 530 天 连续签到: 2 天 [LV.9]测试副司令
|
1测试积点
我这里创建了两个线程,它就重复输入了两次。
- import sys
- from PyQt5 import QtCore, QtGui, QtWidgets, uic
- from selenium import webdriver
- from PyQt5.QtWidgets import QApplication
- from PyQt5.QtCore import QThread, pyqtSignal
- from selenium.webdriver import ChromeOptions
- from fake_useragent import UserAgent
- import time
- import requests
- from zmq import proxy
- from threading import Thread
-
-
-
- # 加载UI文件
- class Stats:
-
-
- def __init__(self):
- self.ui = uic.loadUi('Click_Ui.ui')
- # 自定义信号的处理函数
- # so.breakSignal.connect(self.printToGui)
- self.intUI() # 控件默认参数
- self.But_c() # 按钮事件
-
- # 控件默认参数
- def intUI(self):
- # self.ui.url_lineEdit.setPlaceholderText('请在这里输入58网址,例如:https://cd.58.com/') # 默认提示
- self.ui.url_lineEdit.setText('https://cd.58.com/') # 默认设置可以修改
- self.ui.reg_lineEdit.setText('武侯')
- self.ui.exc_comboBox.addItems(['好又快服务']) # 添加商家
- self.ui.key_lineEdit.setText('管道疏通') # 设置关键词
- # 进度条默认设置
- self.pv = 0
- self.ui.progressBar.setRange(0,100)
- self.ui.progressBar.setValue(self.pv)
- # 按钮默认设置
- self.ui.startButton.setText('开始')
- # 提示
- self.ui.spinBox_2.setValue(5)
- self.ui.spinBox.setValue(3)
-
- # 进度条
- def pgbar(self):
- if self.ui.startButton.text() == '开始':
- self.ui.progressBar.setValue(0)
- self.ui.startButton.setText('停止')
- # 启动脚本
- self.xc()
-
- else:
- self.ui.startButton.setText('开始')
-
- # 开始按钮连接
- def But_c(self):
- self.ui.startButton.clicked.connect(self.pgbar) # 开始按钮连接进度条
- # self.ui.detButton.clicked.connect(self.Api_kd) # 检测按钮
-
- # 接收控件参数
- def kj_cs(self):
- self.url = self.ui.url_lineEdit.text() # 目标网址
- self.key = self.ui.key_lineEdit.text() # 关键词
- self.reg = self.ui.reg_lineEdit.text() # 服务区域
- self.exc = self.ui.exc_comboBox.currentText() # 排除商家
-
- def Bro_s(self):
- self.kj_cs()
- options = ChromeOptions()
- options.add_argument('user-agent=%s' % UserAgent().random)
- self.driver = webdriver.Chrome(options=options)
- self.driver.get('http://httpbin.org/ip')
-
- time.sleep(2)
- self.driver.get(self.url) # 传入目标网址
- time.sleep(3)
- self.driver.find_element_by_id('keyword').send_keys(self.key)
-
- # 创建线程
- def xc(self):
- try:
- for j in range(2):
- t = Thread(target=self.Bro_s)
- t.start()
- except:
- print('无法启动')
-
-
- # 开始程序
- if __name__ == '__main__':
- App = QApplication(sys.argv)
- stats = Stats()
- stats.ui.show()
- sys.exit(App.exec_())
-
-
复制代码
|
|