把以上三个文件放到personData目录下即可。
Admin.pyw
# coding: utf-8
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import os,sys,time,json
import lxml.html
reload(sys)
sys.setdefaultencoding("utf-8")
class mat(QDialog):
def __init__(self):
super(mat, self).__init__()
self.initUI()
def initUI(self):
self.setWindowTitle(u"客户端")
self.setWindowFlags(Qt.Window)
self.ListHtml=getHtml()
self.setWindowTitle(u"管理端")
self.setWindowFlags(Qt.Window)
labelTime=QLabel(u"日期:")
labelNmae=QLabel(u"姓名:")
labelContent=QLabel(u"职务:")
htmlName=QLabel(u'姓名')
self.editName=QLineEdit()
htmlSex=QLabel(u'性别')
self.editSex=QLineEdit()
htmlMinzu=QLabel(u'民族')
self.editMinzu=QLineEdit()
htmlHeight=QLabel(u'身高')
self.editHeight=QLineEdit()
htmlZhiwei=QLabel(u'职务')
self.editZhiwei=QLineEdit()
htmlMianmao=QLabel(u'面貌')
self.editMianmao=QLineEdit()
htmlXuezhi=QLabel(u'学制')
self.editXuezhi=QLineEdit()
htmlXueli=QLabel(u'学历')
self.editXueli=QLineEdit()
htmlEndtime=QLabel(u'毕业时间')
self.editEndtime=QLineEdit()
htmlHuji=QLabel(u'户籍')
self.editHuji=QLineEdit()
htmlBirdate=QLabel(u'出生日期')
self.editBirdate=QLineEdit()
htmlZhuangye=QLabel(u'专业')
self.editZhuangye=QLineEdit()
htmlSchool=QLabel(u'毕业学校')
self.editSchool=QLineEdit()
htmlAddress=QLabel(u'通信地址')
self.editAddress=QLineEdit()
htmlPhone=QLabel(u'联系电话')
self.editPhone=QLineEdit()
htmlEmail=QLabel(u'E-mail ')
self.editEmail=QLineEdit()
htmlYoubian=QLabel(u' 邮编 ')
self.editYoubian=QLineEdit()
self.timeEdit=QComboBox()
self.nameEdit=QComboBox()
self.contentEdit=QComboBox()
self.dataRead()
lay1=QHBoxLayout()
lay1.addWidget(labelTime)
lay1.addWidget(self.timeEdit)
lay2=QHBoxLayout()
lay2.addWidget(labelNmae)
lay2.addWidget(self.nameEdit)
lay3=QHBoxLayout()
lay3.addWidget(labelContent)
lay3.addWidget(self.contentEdit)
Layout=QVBoxLayout()
Layout.addLayout(lay1)
Layout.addLayout(lay2)
Layout.addLayout(lay3)
lat1=QHBoxLayout()
lat1.addWidget(htmlName)
lat1.addWidget(self.editName)
lat1.addWidget(htmlSex)
lat1.addWidget(self.editSex)
lat1.addWidget(htmlMinzu)
lat1.addWidget(self.editMinzu)
lat2=QHBoxLayout()
lat2.addWidget(htmlHeight)
lat2.addWidget(self.editHeight)
lat2.addWidget(htmlZhiwei)
lat2.addWidget(self.editZhiwei)
lat2.addWidget(htmlMianmao)
lat2.addWidget(self.editMianmao)
lat3=QHBoxLayout(htmlXuezhi)
lat3.addWidget(self.editXuezhi)
lat3.addWidget(self.editXuezhi)
lat3.addWidget(htmlXueli)
lat3.addWidget(self.editXueli)
lat3.addWidget(htmlEndtime)
lat3.addWidget(self.editEndtime)
lat4=QHBoxLayout()
lat4.addWidget(htmlHuji)
lat4.addWidget(self.editHuji)
lat4.addWidget(htmlBirdate)
lat4.addWidget(self.editBirdate)
lat5=QHBoxLayout()
lat5.addWidget(htmlZhuangye)
lat5.addWidget(self.editZhuangye)
lat5.addWidget(htmlSchool)
lat5.addWidget(self.editSchool)
lat6=QHBoxLayout()
lat6.addWidget(htmlAddress)
lat6.addWidget(self.editAddress)
lat6.addWidget(htmlPhone)
lat6.addWidget(self.editPhone)
lat7=QHBoxLayout()
lat7.addWidget(htmlEmail)
lat7.addWidget(self.editEmail)
lat7.addWidget(htmlYoubian)
lat7.addWidget(self.editYoubian)
layout=QVBoxLayout()
layout.addLayout(lat1)
layout.addLayout(lat2)
layout.addLayout(lat3)
layout.addLayout(lat4)
layout.addLayout(lat5)
layout.addLayout(lat6)
layout.addLayout(lat7)
mainLayout=QHBoxLayout(self)
mainLayout.addLayout(Layout)
mainLayout.addLayout(layout)
self.setLayout(mainLayout)
self.timeEdit.currentIndexChanged.connect(self.pro_re)
self.nameEdit.currentIndexChanged.connect(self.pro1_re)
self.contentEdit.currentIndexChanged.connect(self.pro2_re)
self.resize(650,450)
def dataRead(self):
dict_all = self.ListHtml
for id in dict_all:
self.timeEdit.addItem(id[-1][-1])
self.nameEdit.addItem(id[0][1])
self.contentEdit.addItem(id[1][3])
def pro_re(self):
index=self.timeEdit.currentIndex()
self.nameEdit.setCurrentIndex(index)
self.contentEdit.setCurrentIndex(index)
getName=str(self.nameEdit.currentText())
getTime=str(self.timeEdit.currentText())
getContent=str(self.contentEdit.currentText())
dict_all = self.ListHtml
for id in dict_all:
if id[0][1]==getName and id[-1][-1]==getTime and id[1][3]==getContent:
self.editName.setText(id[0][1])
self.editSex.setText(id[0][3])
self.editMinzu.setText(id[0][5])
self.editHeight.setText(id[1][1])
self.editZhiwei.setText(id[1][3])
self.editMianmao.setText(id[1][5])
self.editHuji.setText(id[3][1])
self.editBirdate.setText(id[3][3])
self.editZhuangye.setText(id[4][1])
self.editSchool.setText(id[4][3])
self.editAddress.setText(id[7][1])
self.editPhone.setText(id[7][3])
self.editEmail.setText(id[8][1])
self.editYoubian.setText(id[8][3])
def pro1_re(self):
index=self.nameEdit.currentIndex()
self.timeEdit.setCurrentIndex(index)
self.contentEdit.setCurrentIndex(index)
getName=str(self.nameEdit.currentText())
getTime=str(self.timeEdit.currentText())
getContent=str(self.contentEdit.currentText())
dict_all = self.ListHtml
for id in dict_all:
if id[0][1]==getName and id[-1][-1]==getTime and id[1][3]==getContent:
self.editName.setText(id[0][1])
self.editSex.setText(id[0][3])
self.editMinzu.setText(id[0][5])
self.editHeight.setText(id[1][1])
self.editZhiwei.setText(id[1][3])
self.editMianmao.setText(id[1][5])
self.editHuji.setText(id[3][1])
self.editBirdate.setText(id[3][3])
self.editZhuangye.setText(id[4][1])
self.editSchool.setText(id[4][3])
self.editAddress.setText(id[7][1])
self.editPhone.setText(id[7][3])
self.editEmail.setText(id[8][1])
self.editYoubian.setText(id[8][3])
def pro2_re(self):
index=self.contentEdit.currentIndex()
self.nameEdit.setCurrentIndex(index)
self.timeEdit.setCurrentIndex(index)
getName=str(self.nameEdit.currentText())
getTime=str(self.timeEdit.currentText())
getContent=str(self.contentEdit.currentText())
dict_all = self.ListHtml
for id in dict_all:
if id[0][1]==getName and id[-1][-1]==getTime and id[1][3]==getContent:
self.editName.setText(id[0][1])
self.editSex.setText(id[0][3])
self.editMinzu.setText(id[0][5])
self.editHeight.setText(id[1][1])
self.editZhiwei.setText(id[1][3])
self.editMianmao.setText(id[1][5])
self.editHuji.setText(id[3][1])
self.editBirdate.setText(id[3][3])
self.editZhuangye.setText(id[4][1])
self.editSchool.setText(id[4][3])
self.editAddress.setText(id[7][1])
self.editPhone.setText(id[7][3])
self.editEmail.setText(id[8][1])
self.editYoubian.setText(id[8][3])
def getHtml():
upDid= os.path.abspath(os.path.join(os.path.dirname(__file__),"."))
htmlDid=upDid+"\\personData"
getdir=os.listdir(htmlDid)
#print getdir
listHtml=[]
for id in getdir:
if id.split('.')[-1]=="html":
importPath=htmlDid+"\\"+id
doc = lxml.html.parse(importPath)
a=[[j for j in i.xpath('td/a[not(contains(.,"spam"))]/@href | td[not(a)]/text()')] for i in doc.xpath('//tr')]
listHtml.append(a)
return (listHtml)
def main():
app = QApplication(sys.argv)
ex = mat()
ex.show()
app.exec_()
if __name__ == '__main__':
main()
admin.py会自动遍历personData目录下的html文件,并捕获信息,设置到界面上。
如果想要添加模板,打开html修改信息另存即可,名字随意。
运行admin.py下次就回把模板的信息设置到界面上。
moban
<!-- saved from url=(0172)file:///C:/Users/Administrator/Desktop/%E5%BD%B1%E8%A7%86%E7%89%B9%E6%95%88%E8%AF%BE%E7%A8%8B%E8%AE%BE%E8%AE%A1/%E7%AE%80%E5%8E%86%E7%B3%BB%E7%BB%9F/personData/jianli1.html -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=GBK"><title>简历</title>
<style type="text/css">
body,td,th {
font-size: 16px;
color: #000;
}
</style>
</head>
<body>
<center>
<form>
<p><b>个人简历</b></p>
<table cellpadding="0" cellspacing="0" border="1">
<tbody><tr>
<td width="64" height="33">姓名</td>
<td width="109" contenteditable="true"></td>
<td width="73">性别</td>
<td width="46" contenteditable="true">男</td>
<td width="112">民族</td>
<td width="159" contenteditable="true"></td>
<td width="154" rowspan="4"><p><img src="./moban_files/3c1dd7d958c7dc47a2b707e8a72b5e64.jpg" width="154" height="203"></p></td>
</tr>
<tr>
<td height="31">身高</td>
<td contenteditable="true"></td>
<td>职位</td>
<td contenteditable="true">学生</td>
<td>政治面貌</td>
<td contenteditable="true"></td>
</tr>
<tr>
<td height="31">学制</td>
<td contenteditable="true"></td>
<td>学历</td>
<td contenteditable="true">本科</td>
<td>毕业时间</td>
<td contenteditable="true"></td>
</tr>
<tr>
<td height="46">户籍</td>
<td colspan="3" contenteditable="true"></td>
<td>出生年月</td>
<td contenteditable="true"></td>
</tr>
<tr>
<td height="39">专业</td>
<td contenteditable="true"></td>
<td>毕业学校</td>
<td colspan="2" contenteditable="true"></td>
<td>就业范围</td>
<td contenteditable="true"></td>
</tr>
<tr>
<td height="39">外语水平</td>
<td colspan="3" contenteditable="true">四级</td>
<td>计算机水平</td>
<td colspan="2" contenteditable="true"></td>
</tr>
<tr>
<td>奖励情况</td>
<td colspan="6" contenteditable="true"></td>
</tr>
<tr>
<td>通讯地址</td>
<td colspan="4" contenteditable="true"></td>
<td>联系电话</td>
<td contenteditable="true"></td>
</tr>
<tr>
<td>E-mail</td>
<td colspan="3" contenteditable="true"></td>
<td>邮编</td>
<td contenteditable="true"></td>
<td> </td>
</tr>
<tr>
<td height="28" colspan="7">教育经历</td>
</tr>
<tr>
<td colspan="7" contenteditable="true"></td>
</tr>
<tr>
<td colspan="4">日期</td>
<td colspan="3" contenteditable="true"></td>
</tr>
</tbody></table>
<p> </p>
</form>
</center>
</body></html>