学python两个月做了一个查询快递小工具(大佬勿喷)带gui界面
本帖最后由 cdsgg 于 2020-12-7 16:50 编辑首次使用 可能要下载配置文件 卡顿很正常
# -*- 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: () => , }); }''')
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}')
list2 =
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')
await page.type('input', odd)
await page.click('span', button='left')
await asyncio.sleep(0.5)
# await page.waitForSelector('div>div')
content = await page.content()
soup = BeautifulSoup(content, 'lxml')
res = soup.select('ul>li>span')
list1 = []
list2 = []
dict1 = {}
for x in res:
list1.append(x.text)
res2 = soup.select('ul>li>span')
for i in res2:
list2.append(i.text)
ResultsOf = soup.select('div')
for i in ResultsOf:
# print(f'快递公司:{i.text}\n单号:{odd}记录')
# print('===================================')
# for j in range(len(list1)):
# print(f'{list2}:{list1}')
# print('****************************************************')
# print("信息来源:菜鸟裹裹-----阿里巴巴旗下菜鸟网络官方出品")
dict1['快递公司'] = str(i.text)
for o in range(len(list1)):
dict1}'] = list1
# 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 惠民人家 发表于 2020-12-2 19:41
问一句,不是有菜鸟裹裹吗,这 用处不大 谢谢了
练手就行 您好,
我最近基于mimio搭建了一个图床(类似阿里云oss对象存储),然后用python写了上传图片到mimio的一套流程,现在就差封装了,不知道您有兴趣一起合作完善这个代码呢?
我还不够权限发信息,烦请留言一下 ,谢谢 学习使人进步,楼主加油! 哈哈我写的跟屎一样 我觉得丢人 666这么厉害 老哥怎么打包成程序 厉害子,学习学习 yzqhj 发表于 2020-12-2 18:30
老哥怎么打包成程序
Pyinstaller -w 你保存的名字.py cdsgg 发表于 2020-12-2 18:33
Pyinstaller -w 你保存的名字.py
终端命令?需要安装什么么? yzqhj 发表于 2020-12-2 18:36
终端命令?需要安装什么么?
pip install Pyinstaller
已经很不错了,我学这么长时间还啥也不会呢