win32api.keybd_event(17, 0, 0, 0) win32api.keybd_event(18, 0, 0, 0) win32api.keybd_event(90, 0, 0, 0) win32api.keybd_event(90, 0, win32con.KEYEVENTF_KEYUP, 0) win32api.keybd_event(18, 0, win32con.KEYEVENTF_KEYUP, 0) win32api.keybd_event(17, 0, win32con.KEYEVENTF_KEYUP, 0)
===========
# -*- coding: utf-8 -*- """ Module implementing New_52pojie. """ from PyQt5.QtCore import * from PyQt5.QtWidgets import * from PyQt5.QtGui import * from openpyxl import load_workbook, Workbook, styles from openpyxl.styles import NumberFormatDescriptor from Ui_New_Info_52pojie_Ui import Ui_Dialog import requests, re, sys from bs4 import BeautifulSoup class New_52pojie(QDialog, Ui_Dialog): """ Class documentation goes here. """ def __init__(self, parent=None): """ Constructor @param parent reference to the parent widget @type QWidget """ super(New_52pojie, self).__init__(parent) self.setupUi(self) self.session = requests.session() self.model = QStandardItemModel(30, 4) self.model.setHorizontalHeaderLabels(['标题', '区域', '作者', '时间']) self.url='https://www.52pojie.cn/forum.php?mod=guide&view=newthread&page=' self.pushButton_start.clicked.connect(self.onPushButton_startClick) self.pushButton_nextPage.clicked.connect(self.onPushButton_nextClick) self.pushButton_previousPage.clicked.connect(self.onPushButton_previousClick) self.pushButton_excel.clicked.connect(self.onPushButton_excelClick) self.times=1 def get_(self, url='https://www.52pojie.cn/forum.php?mod=guide&view=newthread'): r = self.session.get(url) #print(r.text) soup = BeautifulSoup(r.text,'lxml') all_tz = soup.findAll(attrs={"id": re.compile(r"normalthread_(\d+){,10}")}) data=[] for tz in all_tz: tz = tz.find('tr') #url = tz.find('th',class_='common').find('a').get('href') title = tz.find('th',class_='common').find('a').get_text().strip() area = tz.find_all('td',class_='by')[0].find('a').get_text().strip() start_username = tz.find_all('td',class_='by')[1].find('cite').get_text().strip() start_time = tz.find_all('td',class_='by')[1].find('em').get_text().strip() #last_username = tz.find_all('td',class_='by')[-1].find('cite').get_text().strip() #last_time = tz.find_all('td',class_='by')[-1].find('em').get_text().strip() #answer_number = tz.find('td',class_='num').find('a').get_text().strip() #print(title,start_username,start_time,area) data.append({'title':title,'start_username':start_username,'start_time':start_time,'area':area}) return data def Use_data(self, data): for row in range(len(data)): a=0 for colum in ['title', 'area', 'start_username', 'start_time']: #print(data[row][colum]) item = QStandardItem(data[row][colum]) self.model.setItem(row, a, item) a+=1 # for i in range(5): # self.model.appendRow([ # QStandardItem(data[i]['title'], data[i]['area'], data[i]['start_username'], data[i]['start_time']') #]) #self.tableView=QTableView() self.tableView.horizontalHeader().setStretchLastSection(True) self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.tableView.setModel(self.model) dlgLayout = QVBoxLayout() dlgLayout.addWidget(self.tableView) self.setLayout(dlgLayout) def onPushButton_startClick(self): """ Slot documentation goes here. """ self.times = 1 data=self.get_() self.Use_data(data) def onPushButton_nextClick(self): self.times+=1 print(self.times) if self.times>=1 and self.times<=8: self.Use_data(self.get_(url=self.url+str(self.times))) else: self.times=8 self.label_info.setText('已经最后一页了!') def onPushButton_previousClick(self): self.times-=1 print(self.times) if self.times>=1 and self.times<=8: self.Use_data(self.get_(url=self.url+str(self.times))) else: self.times=1 self.label_info.setText('已经第一页了!') def onPushButton_excelClick(self): wb = Workbook() ws = wb.active # ws.append(['1234']) # wb.save('123.xlsx') # indexs=self.tableView.selectionModel().selection().indexes() # if len(indexs)>0: # index = indexs[0] # self.model.removeRows(index.row(),1) #index=self.tableView.currentIndex() for row_ in range(0, self.model.rowCount()): for column_ in range(0, self.model.columnCount()): print(row_, self.model.data(self.model.index(row_, column_))) ws.cell(row=row_+1, column=column_+1).value=self.model.data(self.model.index(row_, column_)) ws.cell(row=row_+1, column=column_+1).style.number_format.format_code = NumberFormatDescriptor.FORMAT_TEXT #self.model.removeRow(index.row()) #print(self.model.data(self.model.index())) wb.save('123.xlsx') print(self.model.rowCount()) if __name__=="__main__": app = QApplication(sys.argv) myWin = New_52pojie() myWin.show() sys.exit(app.exec_())
from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtWebEngineWidgets import * from PyQt5.QtNetwork import * import sys class MyMain(QWidget): def __init__(self, parent=None): super(MyMain, self).__init__(parent) self.setWindowTitle('快捷复制') self.wwg = QWidget(self) self.wlayout = QVBoxLayout(self.wwg)#全局排列 self.endLabel = QLabel('结果') self.endEdit = QTextEdit() self.topcheckbox = QCheckBox('窗口置顶') self.toplabel1 = QLabel('透明度:') self.toplabel2 = QLabel() self.slidertop = QSlider(Qt.Horizontal) self.slidertop.setMinimum(10) self.slidertop.setMaximum(100) self.slidertop.setValue(100) self.topcheckbox.stateChanged.connect(self.checkboxchange) self.slidertop.valueChanged.connect(self.valuechange) self.count = 0 self.btn_count = 0 self.counth = 0 self.counth1 = 0 top_w = QWidget() top_layout = QHBoxLayout() top_layout.addWidget(self.topcheckbox) top_layout.addWidget(self.slidertop) top_layout.addWidget(self.toplabel1) top_layout.addWidget(self.toplabel2) top_w.setLayout(top_layout) self.wlayout.addWidget(top_w) #self.resize(700, 400) self.all_data = self.data_to_dict() self.all_title = {} self.all_add() end_w = QWidget()#结果栏 end_layout = QHBoxLayout() end_layout.addWidget(self.endLabel) end_layout.addWidget(self.endEdit) end_w.setLayout(end_layout) self.wlayout.addWidget(end_w) self.setLayout(self.wlayout) def all_add(self): for type_ in self.all_data:#循环字典分类 print(type_) type_w = QWidget()#定义窗口 title_w = QWidget() type_and_title_w = QWidget() type_layout = QHBoxLayout()#分类label完成 type_layout.addWidget(QLabel(type_)) #type_w.setMaximumWidth(100) type_w.setLayout(type_layout) title_layout = QGridLayout() self.counth = 0 self.counth1 = 0 for title_ in self.all_data[type_]: #self.count = 0 self.btn_count = len(self.all_data[type_]) if self.btn_count > 6: self.counth=divmod(self.count,3)[0] self.btn1(title_, title_layout, type_) else: self.btn(title_,title_layout,type_) title_w.setLayout(title_layout) type_and_title_layout = QHBoxLayout()#分类+标题完成 type_and_title_layout.addWidget(type_w) type_and_title_layout.addWidget(title_w) type_and_title_w.setLayout(type_and_title_layout) self.wlayout.addWidget(type_and_title_w)#全局布局添加 def btn(self,title_,title_layout,type_key): title_btn = QPushButton('&' + title_) # title_btn.setMaximumWidth(150) title_btn.setMaximumSize(100,25) title_btn.setMinimumSize(100,25) self.all_title['&'+title_] = self.all_data[type_key][title_]#创建字典,方便后续复制查找 # print(self.all_title['&'+title_]) # dict1_button[title_] = all_data[type_][title_] title_btn.clicked.connect(lambda: self.get_titlenr(title_btn)) # title_layout.addWidget(title_btn) title_layout.addWidget(title_btn,0,self.count) self.count+=1 def btn1(self,title_,title_layout,type_key): title_btn = QPushButton('&' + title_) self.all_title['&'+title_] = self.all_data[type_key][title_]#创建字典,方便后续复制查找 # print(self.all_title['&'+title_]) # dict1_button[title_] = all_data[type_][title_] title_btn.clicked.connect(lambda: self.get_titlenr(title_btn)) # title_layout.addWidget(title_btn) title_layout.addWidget(title_btn,self.btn_counth,self.count) self.count+=1 def checkcount(self,numb): if numb<=3: return [0,numb] else: return [divmod(numb,3)] def get_titlenr(self,btn): # print(nr.text()) # print(nr) self.endEdit.setText(self.all_title[btn.text()]) clipboard = QApplication.clipboard() clipboard.setText(self.all_title[btn.text()]) def checkboxchange(self): if self.topcheckbox.isChecked(): self.setWindowFlags(Qt.WindowStaysOnTopHint) self.show() else: pass def valuechange(self): current = self.slidertop.value() self.toplabel2.setText(str(current)+'%') #print(type(current)) self.setWindowOpacity(current/100) def data_to_dict(self): all_type = [] file = open('data.txt', 'r') all_data = file.readlines() file.close() for i in all_data: type = i.split('|')[0].strip() if type not in all_type and len(type) > 0: all_type.append(type) la = {} for i in all_type: la[i] = {} for i in all_data: try: la[i.split('|')[0]][i.split('|')[1]] = i.split('|')[2].strip() except IndexError: pass return la if __name__ == '__main__': app = QApplication(sys.argv) MyWin = MyMain() MyWin.show() sys.exit(app.exec_())
http://blog.csdn.net/mzbqhbc12/article/details/54946647
http://blog.sina.com.cn/s/blog_3fe961ae0102uzh8.html
http://blog.csdn.net/bluehawksky/article/details/44957627