Modules used

Requests PyQt5 comes with PythonCopy the code

Python version: 3.6.4

The principle of

Climb express 100, www.kuaidi100.com/, climb express information is very simple, only according to the express tracking number to obtain its possible owning express company, and then obtain the data of the express tracking number of these express companies can be. \

It can be seen that the first request, according to the order number query express company, and returned is pinyin. For example, it is Zhongtong Express in the picture, and zhongtong is returned. The second request was made according to the express company and the tracking number. Logistics information is returned.

The code implements the first request

"" def getExpressInfo(number): url = 'http://www.kuaidi100.com/autonumber/autoComNum?resultv2=1&text=%s' % number infos = [] for each in requests.get(url).json()['auto']: company_name = each['comCode']Copy the code

The code implements the second request

url = 'http://www.kuaidi100.com/query?type=%s&postid=%s' % (company_name, Number) temps = request.get (url).json()['data'] info = 'company: %s\n' % py2hz(company_name) for idx, each in enumerate(temps): if idx == 0: The info + = '-' * 60 + '\ n time: \ n + each [' time'] + 'progress: \ n \ n + each [' context'] + '\ n' + '-' * 60 + '\ n' else: The info + = 'time: \ n + each [' time'] + 'progress: \ n \ n + each [' context'] + '\ n' + '-' * 60 + '\ n' if not temps: Info + = '-' * 60 + '\ n' + 'number does not exist or has expired \ n' + '-' * 60 + '\ n' infos. Append (info)Copy the code

Note here that the first request and the second request should be written in one method. And there’s a way to do it.

Pinyin to Chinese

companies = pickle.load(open('companies.pkl', 'rb'))
def py2hz(py):
    return companies.get(py)
Copy the code

Finally, you can build an interface with PyQt5

Interface structures,

class Demo(QWidget): def __init__(self, parent=None): Super ().__init__() self.setwindowTitle (' Express query system ') self.label1 = QLabel(' express tracking number :') self.line_edit = QLineEdit() self.label2 Self.text = QTextEdit() self.button = QPushButton() self.button.settext (' query ') 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(200, 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 '+' number does not exist or has expired \ n '+' - '* 60 +' \ n '] except: Infos = [' - '* 60 +' \ n '+' express a single number is wrong, please input again. \ n '+' - '* 60 +' \ n '] self. The text. The setText (' \ n \ n \ n '. Join (infos)] [: - 1)Copy the code

Obtain source code private I “tracking number”