吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 8692|回复: 87
收起左侧

[Python 转载] 学python两个月做了一个查询快递小工具(大佬勿喷)带gui界面

[复制链接]
cdsgg 发表于 2020-12-2 18:20
本帖最后由 cdsgg 于 2020-12-7 16:50 编辑



首次使用 可能要下载配置文件 卡顿很正常


[Python] 纯文本查看 复制代码
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'expressQuery.ui'
#
# Created by: PyQt5 UI code generator 5.15.1
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
import sys
import requests
import tkinter
import asyncio
from pyppeteer import launch
import time
from bs4 import BeautifulSoup


def screen_size():
    tk = tkinter.Tk()
    width = tk.winfo_screenwidth()
    height = tk.winfo_screenheight()
    tk.quit()
    return {'width': width, 'height': height}


async def mainProgram3():
    global page
    global browser
    browser = await launch(headless=True, args=['--start-maximized'],
                           ignoreDefaultArgs=['--enable-automation'])  # 页面全屏
    page = await browser.newPage()

    await page.setViewport(screen_size())
    # await page.setCookie({'cookie': 'ALF=1607876296; WEIBOCN_FROM=1110003030; SUB=_2A25yvNZfDeRhGeFO61cR-SnMzDqIHXVuXvoXrDV6PUJbkdANLUPekW1NQYXJAY4sVZJyyWrZmdiOCd7yq2S5YMEs; _T_WM=85956253883; MLOGIN=1; XSRF-TOKEN=dd7c1c; M_WEIBOCN_PARAMS=luicode%3D20000174%26lfid%3D1008088e92193d0e74d876aa8aaee841021081_-_feed%26uicode%3D20000174'}) # 内容全屏
    await page.goto('https://www.guoguo-app.com/')
    await page.evaluate(
        '''() =>{ Object.defineProperties(navigator,{ webdriver:{ get: () => false } }) }''')  # 以下为插入中间js,将淘宝会为了检测浏览器而调用的js修改其结果。
    await page.evaluate('''() =>{ window.navigator.chrome = { runtime: {},  }; }''')
    await page.evaluate(
        '''() =>{ Object.defineProperty(navigator, 'languages', { get: () => ['en-US', 'en'] }); }''')
    await page.evaluate(
        '''() =>{ Object.defineProperty(navigator, 'plugins', { get: () => [1, 2, 3, 4, 5,6], }); }''')
    await page.evaluate('window.scrollTo(0,document.body.scrollHeight)')


asyncio.get_event_loop().run_until_complete(mainProgram3())


class Ui_singlenumberinput(object):
    def setupUi(self, singlenumberinput):
        singlenumberinput.setObjectName("singlenumberinput")
        singlenumberinput.resize(466, 388)
        self.CourierCompany = QtWidgets.QLineEdit(singlenumberinput)
        self.CourierCompany.setGeometry(QtCore.QRect(160, 49, 131, 20))
        self.CourierCompany.setObjectName("CourierCompany")
        self.inputNumber = QtWidgets.QLabel(singlenumberinput)
        self.inputNumber.setGeometry(QtCore.QRect(90, 49, 60, 23))
        self.inputNumber.setAlignment(QtCore.Qt.AlignCenter)
        self.inputNumber.setObjectName("inputNumber")
        self.ReturnsResult = QtWidgets.QTextBrowser(singlenumberinput)
        self.ReturnsResult.setGeometry(QtCore.QRect(50, 84, 361, 295))
        self.ReturnsResult.setObjectName("ReturnsResult")
        self.widget = QtWidgets.QWidget(singlenumberinput)
        self.widget.setGeometry(QtCore.QRect(90, 7, 282, 25))
        self.widget.setObjectName("widget")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.singleNumberInput = QtWidgets.QLabel(self.widget)
        self.singleNumberInput.setAlignment(QtCore.Qt.AlignCenter)
        self.singleNumberInput.setObjectName("singleNumberInput")
        self.horizontalLayout.addWidget(self.singleNumberInput)
        self.oddip = QtWidgets.QLineEdit(self.widget)
        self.oddip.setObjectName("oddip")
        self.horizontalLayout.addWidget(self.oddip)
        self.pushButton = QtWidgets.QPushButton(self.widget)
        self.pushButton.setObjectName("pushButton")
        self.horizontalLayout.addWidget(self.pushButton)
        self.pushButton.clicked.connect(self.run)

        self.retranslateUi(singlenumberinput)
        QtCore.QMetaObject.connectSlotsByName(singlenumberinput)

    def retranslateUi(self, singlenumberinput):
        _translate = QtCore.QCoreApplication.translate
        singlenumberinput.setWindowTitle(_translate("singlenumberinput", "单号查询小工具"))
        self.inputNumber.setText(_translate("singlenumberinput", "快递公司:"))
        self.singleNumberInput.setText(_translate("singlenumberinput", "输入单号:"))
        self.pushButton.setText(_translate("singlenumberinput", "查询"))

    def run(self):
        danhao = self.oddip.text()
        a = asyncio.get_event_loop().run_until_complete(mainProgram2(danhao))
        list1 = []
        self.CourierCompany.setText(a['快递公司'])
        for key in a:
            list1.append(f'{key}:{a[key]}')
        list2 = [str(k) for k in list1]
        list3 = ' \n'.join(list2)
        self.ReturnsResult.setText(f'{list3}')

    def PopupWindow(self):
        QMessageBox.information(w, '提示', '信号接收成功')


class MyWidget(QMainWindow):
# """
# 重写closeEvent方法
# """
    def closeEvent(self, event):
        result = QtWidgets.QMessageBox.question(self, "标题", "亲,你确定想关闭我?别后悔!!!'_'", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
        if result == QtWidgets.QMessageBox.Yes:
            browser.close()
            event.accept()
            # 通知服务器的代码省略,这里不是重点...
        else:
            event.ignore()


async def mainProgram2(oddep):
    odd = oddep
    # await asyncio.sleep(1)
    # await page.waitForSelector('input[id="J_SearchInput"]')
    await page.type('input[id="J_SearchInput"]', odd)
    await page.click('span[id="J_SearchBtn"]', button='left')
    await asyncio.sleep(0.5)
    # await page.waitForSelector('div[class="cp-detail"]>div[class="cp-name"]')
    content = await page.content()
    soup = BeautifulSoup(content, 'lxml')
    res = soup.select('ul[id="J_PackageDetail"]>li>span[class="text"]')
    list1 = []
    list2 = []
    dict1 = {}
    for x in res:
        list1.append(x.text)
    res2 = soup.select('ul[id="J_PackageDetail"]>li>span[class="date"]')
    for i in res2:
        list2.append(i.text)
    ResultsOf = soup.select('div[class="cp-name"]')
    for i in ResultsOf:
        # print(f'快递公司:{i.text}\n单号:{odd}记录')
        # print('===================================')
        # for j in range(len(list1)):
        #     print(f'{list2[j]}:{list1[j]}')
        # print('****************************************************')
        # print("信息来源:菜鸟裹裹-----阿里巴巴旗下菜鸟网络官方出品")
        dict1['快递公司'] = str(i.text)

    for o in range(len(list1)):
        dict1[f'{list2[o]}'] = list1[o]
    # print(dict1)
    dict1['信息来源'] = '菜鸟裹裹-----阿里巴巴旗下菜鸟网络官方出品'
    # await page.reload()
    await page.evaluate('document.querySelector("#J_SearchInput").value=""')

    # print(dict1)
    # list3 = zip(list1, list2)
    return dict1


if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = MyWidget()
    UI = Ui_singlenumberinput()
    slh = asyncio.get_event_loop()
    UI.setupUi(w)
    w.show()
    app.exec_()


附成品链接:
https://wwa.lanzouj.com/ieBuJj4g75g
QQ截图20201202182322.png
1.png

免费评分

参与人数 11吾爱币 +11 热心值 +11 收起 理由
DrillAnn + 1 + 1 用心讨论,共获提升!
z331883053 + 1 + 1 用心讨论,共获提升!
zijingyao + 1 + 1 大佬。我学了半个月了。元组还没学会
glocksheep + 1 + 1 刚开始学,谢谢分享
lanhai2020 + 1 + 1 我很赞同!
Fetchens + 1 + 1 我很赞同!
eec + 1 + 1 我很赞同!
hxw0204 + 1 + 1 热心回复!
上青天 + 1 + 1 我很赞同!
浅陌寻 + 1 + 1 用心讨论,共获提升!
难为阿! + 1 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

QingYi. 发表于 2020-12-2 20:44
惠民人家 发表于 2020-12-2 19:41
问一句,不是有菜鸟裹裹吗,这 用处不大 谢谢了

练手就行
zbuhui 发表于 2021-2-9 10:32
您好,
我最近基于mimio搭建了一个图床(类似阿里云oss对象存储),然后用python写了上传图片到mimio的一套流程,现在就差封装了,不知道您有兴趣一起合作完善这个代码呢?
我还不够权限发信息,烦请留言一下 ,谢谢
miqi1314 发表于 2020-12-2 18:21
 楼主| cdsgg 发表于 2020-12-2 18:24
哈哈我写的跟屎一样 我觉得丢人
isugar 发表于 2020-12-2 18:28
666这么厉害
yzqhj 发表于 2020-12-2 18:30
老哥怎么打包成程序
知味8848 发表于 2020-12-2 18:32
厉害子,学习学习
 楼主| cdsgg 发表于 2020-12-2 18:33
yzqhj 发表于 2020-12-2 18:30
老哥怎么打包成程序

Pyinstaller -w 你保存的名字.py
yzqhj 发表于 2020-12-2 18:36
cdsgg 发表于 2020-12-2 18:33
Pyinstaller -w 你保存的名字.py

终端命令?需要安装什么么?
 楼主| cdsgg 发表于 2020-12-2 18:44
yzqhj 发表于 2020-12-2 18:36
终端命令?需要安装什么么?

pip install Pyinstaller
你是我的人 发表于 2020-12-2 18:45
已经很不错了,我学这么长时间还啥也不会呢
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 19:47

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表