正文 作者 :“程序员梨子”
**文章简介 **:本篇文章主要利用pyqt5做一款物流更新、快递查询系统。
**文章源码获取 **: 为了感谢每一个关注我的小可爱每篇文章的项目源码都是无偿分
享滴
点这里蓝色这行字体自取,需要什么源码记得说标题名字哈!私信我也可!
欢迎小伙伴们 点赞、收藏⭐、留言
随着网购的广泛普及,现在大部分年轻人都喜欢上了网购的方式。
很多东西物美价廉,出不出户也能满足你的购买需求!
今天的话小编带大家写一款有界面的专属快递物流查询小系统~再也不用担心自己的快递突然消
失啦!
一、代码实现环境安装:
安装包-Python3、Pycharm2021、模块-requests、pyqt5。
pip install requestspip install pyqt5 #当然镜像源更快安装,环境问题直接找我
(1)首先导入所有快递公司的信息,这是以快递100为例的哈,之前爬的数据。
companies = pickle.load(open('companies.pkl', 'rb'))
(2)利用快递100查询快递。
def getExpressInfo(number):url = 'http://www.kuaidi100.com/autonumber/autoComNum?resultv2=1&text=%s' % numberheaders = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36','Host': 'www.kuaidi100.com'}infos = []for each in requests.get(url, headers=headers).json()['auto']:company_name = each['comCode']url = 'http://www.kuaidi100.com/query?type=%s&postid=%s' % (company_name, number)temps = requests.get(url, headers=headers).json()['data']info = '公司: %sn' % py2hz(company_name)for idx, each in enumerate(temps):if idx == 0:info += '-' * 60 + 'n时间:n' + each['time'] + 'n进度:n' + each['context'] + 'n' + '-' * 60 + 'n'else:info += '时间:n' + each['time'] + 'n进度:n' + each['context'] + 'n' + '-' * 60 + 'n'if not temps:info += '-' * 60 + 'n' + '单号不存在或已过期n' + '-' * 60 + 'n'infos.append(info)return infos
(3)制作快递查询系统的界面。
class ExpressGUI(QWidget):def __init__(self, parent=None):super(ExpressGUI, self).__init__(parent)self.setWindowTitle('快递查询系统')self.label1 = QLabel('快递单号:')self.line_edit = QLineEdit()self.label2 = QLabel('查询结果:')self.text = QTextEdit()self.button = QPushButton()self.button.setText('查询')self.grid = QGridLayout()self.grid.setSpacing(12)self.grid.addWidget(self.label1, 1, 0)self.grid.addWidget(self.line_edit, 1, 1, 1, 39)self.grid.addWidget(self.button, 1, 40)self.grid.addWidget(self.label2, 2, 0)self.grid.addWidget(self.text, 2, 1, 1, 40)self.setLayout(self.grid)self.resize(600, 400)self.button.clicked.connect(self.inquiry)def inquiry(self):number = self.line_edit.text()try:infos = getExpressInfo(number)if not infos:infos = ['-' * 60 + 'n' + '单号不存在或已过期n' + '-' * 60 + 'n']except:infos = ['-' * 60 + 'n' + '快递单号有误, 请重新输入.n' + '-' * 60 + 'n']self.text.setText('nnn'.join(infos)[:-1])
二、效果如下 附主程序源码:
'''Function:快递查询系统源码基地:#959755565#'''import sysimport pickleimport requestsfrom PyQt5.QtWidgets import *'''导入所有快递公司信息'''companies = pickle.load(open('companies.pkl', 'rb'))'''将快递公司的拼音变为汉字'''def py2hz(py):return companies.get(py)'''利用快递100查询快递'''def getExpressInfo(number):url = 'http://www.kuaidi100.com/autonumber/autoComNum?resultv2=1&text=%s' % numberheaders = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36','Host': 'www.kuaidi100.com'}infos = []for each in requests.get(url, headers=headers).json()['auto']:company_name = each['comCode']url = 'http://www.kuaidi100.com/query?type=%s&postid=%s' % (company_name, number)temps = requests.get(url, headers=headers).json()['data']info = '公司: %sn' % py2hz(company_name)for idx, each in enumerate(temps):if idx == 0:info += '-' * 60 + 'n时间:n' + each['time'] + 'n进度:n' + each['context'] + 'n' + '-' * 60 + 'n'else:info += '时间:n' + each['time'] + 'n进度:n' + each['context'] + 'n' + '-' * 60 + 'n'if not temps:info += '-' * 60 + 'n' + '单号不存在或已过期n' + '-' * 60 + 'n'infos.append(info)return infos'''制作简单的GUI'''class ExpressGUI(QWidget):def __init__(self, parent=None):super(ExpressGUI, self).__init__(parent)self.setWindowTitle('快递查询系统')self.label1 = QLabel('快递单号:')self.line_edit = QLineEdit()self.label2 = QLabel('查询结果:')self.text = QTextEdit()self.button = QPushButton()self.button.setText('查询')self.grid = QGridLayout()self.grid.setSpacing(12)self.grid.addWidget(self.label1, 1, 0)self.grid.addWidget(self.line_edit, 1, 1, 1, 39)self.grid.addWidget(self.button, 1, 40)self.grid.addWidget(self.label2, 2, 0)self.grid.addWidget(self.text, 2, 1, 1, 40)self.setLayout(self.grid)self.resize(600, 400)self.button.clicked.connect(self.inquiry)def inquiry(self):number = self.line_edit.text()try:infos = getExpressInfo(number)if not infos:infos = ['-' * 60 + 'n' + '单号不存在或已过期n' + '-' * 60 + 'n']except:infos = ['-' * 60 + 'n' + '快递单号有误, 请重新输入.n' + '-' * 60 + 'n']self.text.setText('nnn'.join(infos)[:-1])'''run'''if __name__ == '__main__':app = QApplication(sys.argv)gui = ExpressGUI()gui.show()sys.exit(app.exec_())
总结这款快递查询小程序,喜欢的找我拿哈!
注小编获取更多精彩内容!记得点击传送门哈记得三连哦! 如需打包好的源码+素材免费分享滴!!传送门