first commit

This commit is contained in:
萌狼蓝天 2024-07-22 15:21:36 +08:00
commit 7450a1debf
23 changed files with 189211 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

21
.idea/ele_fengshen.iml Normal file
View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="Flask">
<option name="enabled" value="true" />
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.12 (ele_fengshen)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_CONFIGURATION" value="Jinja2" />
<option name="TEMPLATE_FOLDERS">
<list>
<option value="$MODULE_DIR$/../ele_fengshen\templates" />
</list>
</option>
</component>
</module>

View File

@ -0,0 +1,88 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="68">
<item index="0" class="java.lang.String" itemvalue="pandas" />
<item index="1" class="java.lang.String" itemvalue="pycryptodome" />
<item index="2" class="java.lang.String" itemvalue="requests" />
<item index="3" class="java.lang.String" itemvalue="urllib3" />
<item index="4" class="java.lang.String" itemvalue="Flask_Cors" />
<item index="5" class="java.lang.String" itemvalue="Jinja2" />
<item index="6" class="java.lang.String" itemvalue="Flask" />
<item index="7" class="java.lang.String" itemvalue="PyMySQL" />
<item index="8" class="java.lang.String" itemvalue="picamera" />
<item index="9" class="java.lang.String" itemvalue="face_recognition_models" />
<item index="10" class="java.lang.String" itemvalue="dlib" />
<item index="11" class="java.lang.String" itemvalue="mysqlclient" />
<item index="12" class="java.lang.String" itemvalue="tzlocal" />
<item index="13" class="java.lang.String" itemvalue="greenlet" />
<item index="14" class="java.lang.String" itemvalue="python-dateutil" />
<item index="15" class="java.lang.String" itemvalue="psycopg2" />
<item index="16" class="java.lang.String" itemvalue="h11" />
<item index="17" class="java.lang.String" itemvalue="MarkupSafe" />
<item index="18" class="java.lang.String" itemvalue="atlastk" />
<item index="19" class="java.lang.String" itemvalue="django-snapshot" />
<item index="20" class="java.lang.String" itemvalue="starlette" />
<item index="21" class="java.lang.String" itemvalue="certifi" />
<item index="22" class="java.lang.String" itemvalue="anyio" />
<item index="23" class="java.lang.String" itemvalue="uvicorn" />
<item index="24" class="java.lang.String" itemvalue="xlrd" />
<item index="25" class="java.lang.String" itemvalue="pydantic" />
<item index="26" class="java.lang.String" itemvalue="markup" />
<item index="27" class="java.lang.String" itemvalue="Werkzeug" />
<item index="28" class="java.lang.String" itemvalue="asgiref" />
<item index="29" class="java.lang.String" itemvalue="cryptography" />
<item index="30" class="java.lang.String" itemvalue="orjson" />
<item index="31" class="java.lang.String" itemvalue="typing-extensions" />
<item index="32" class="java.lang.String" itemvalue="loguru" />
<item index="33" class="java.lang.String" itemvalue="click" />
<item index="34" class="java.lang.String" itemvalue="APScheduler" />
<item index="35" class="java.lang.String" itemvalue="simplejson" />
<item index="36" class="java.lang.String" itemvalue="prettytable" />
<item index="37" class="java.lang.String" itemvalue="aioredis" />
<item index="38" class="java.lang.String" itemvalue="charset-normalizer" />
<item index="39" class="java.lang.String" itemvalue="snapshot" />
<item index="40" class="java.lang.String" itemvalue="idna" />
<item index="41" class="java.lang.String" itemvalue="PyJWT" />
<item index="42" class="java.lang.String" itemvalue="rsa" />
<item index="43" class="java.lang.String" itemvalue="async-timeout" />
<item index="44" class="java.lang.String" itemvalue="SQLAlchemy" />
<item index="45" class="java.lang.String" itemvalue="cffi" />
<item index="46" class="java.lang.String" itemvalue="wcwidth" />
<item index="47" class="java.lang.String" itemvalue="numpy" />
<item index="48" class="java.lang.String" itemvalue="pyasn1" />
<item index="49" class="java.lang.String" itemvalue="importlib-metadata" />
<item index="50" class="java.lang.String" itemvalue="sniffio" />
<item index="51" class="java.lang.String" itemvalue="tortoise" />
<item index="52" class="java.lang.String" itemvalue="zipp" />
<item index="53" class="java.lang.String" itemvalue="pyecharts" />
<item index="54" class="java.lang.String" itemvalue="itsdangerous" />
<item index="55" class="java.lang.String" itemvalue="python-jose" />
<item index="56" class="java.lang.String" itemvalue="tzdata" />
<item index="57" class="java.lang.String" itemvalue="ecdsa" />
<item index="58" class="java.lang.String" itemvalue="python-multipart" />
<item index="59" class="java.lang.String" itemvalue="pytz-deprecation-shim" />
<item index="60" class="java.lang.String" itemvalue="fastapi" />
<item index="61" class="java.lang.String" itemvalue="trustme" />
<item index="62" class="java.lang.String" itemvalue="colorama" />
<item index="63" class="java.lang.String" itemvalue="pytz" />
<item index="64" class="java.lang.String" itemvalue="asyncmy" />
<item index="65" class="java.lang.String" itemvalue="openpyxl" />
<item index="66" class="java.lang.String" itemvalue="pytest-runner" />
<item index="67" class="java.lang.String" itemvalue="pytest" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N802" />
</list>
</option>
</inspection_tool>
</profile>
</component>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="flask311" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (ele_fengshen)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ele_fengshen.iml" filepath="$PROJECT_DIR$/.idea/ele_fengshen.iml" />
</modules>
</component>
</project>

8
README.md Normal file
View File

@ -0,0 +1,8 @@
pip install pipreqs
pipreqs ./
查看当前谷歌浏览器版本 chrome://version/
谷歌驱动
https://googlechromelabs.github.io/chrome-for-testing/

Binary file not shown.

Binary file not shown.

Binary file not shown.

56
app.py Normal file
View File

@ -0,0 +1,56 @@
import configparser
import threading
from flask import Flask
from webdriver_manager.chrome import ChromeDriverManager
import logging
from run_window import open_url_with_selenium
# 创建Flask应用
app = Flask(__name__)
# 读取配置文件
config = configparser.ConfigParser()
config.read('config.ini',encoding="utf-8")
# 从配置文件中读取参数
# 从配置文件中读取参数
url_base = config.get('base', 'url_base')
url_login = r"https://mozi-login.alibaba-inc.com/?APP_NAME=LPD_TEAM_AEOLUS&BACK_URL=https%3A%2F%2Faeolus.ele.me"
url_home = config.get('base', 'url_home')
url_work = config.get('base', 'url_work')
account = config.get('base', 'account')
password = config.get('base', 'password')
interval = int(config.get('base', 'interval'))
driver_type = config.get('base', 'driver')
host = config.get('web', 'host')
port = config.get('web', 'port')
debug = config.get('web', 'debug')
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
# 设置日志记录级别
logging.basicConfig(level=logging.INFO, handlers=[logging.StreamHandler()])
handler = logging.FileHandler('flask.log')
app.logger.addHandler(handler)
# 运行Flask应用
if debug.upper()=="FALSE":
debug = False
else:
debug = True
# 检查驱动
qd_path = ChromeDriverManager().install()
# 检查是否成功获取路径
if not qd_path:
app.logger.error("chrome驱动不存在")
else:
app.logger.info(f"Chromedriver 已安装在 {qd_path}")
# 异步执行selenium操作
threading.Thread(target=open_url_with_selenium, args=(url_base,)).start()
app.run(host=host,port=int(port),debug=debug)
app.logger.info(host+":"+port+" | debug = "+str(debug))

File diff suppressed because it is too large Load Diff

Binary file not shown.

18
config.ini Normal file
View File

@ -0,0 +1,18 @@
[base]
url_base = aeolus.ele.me
url_login = https://mozi-login.alibaba-inc.com/?APP_NAME=LPD_TEAM_AEOLUS&BACK_URL=
url_home = https://aeolus.ele.me/dashboard
url_work = "https://aeolus.ele.me/?targetId=7715#/group/schedule/work-check"
account = 17323612594
password = Cjl1111.
# 浏览器驱动,暂只支持 firefox edge chrome默认
driver = chrome
driver_path_edge = ./edgedriver_win64/msedgedriver.exe
driver_path_chrome = chromedriver-win64/chromedriver.exe
# 间隔时间 单位秒 就是每隔多少秒检查一次数据
interval = 60
[web]
host = 0.0.0.0
port = 8868
debug = True

View File

@ -0,0 +1,55 @@
MICROSOFT SOFTWARE LICENSE TERMS
MICROSOFT EDGE WEBDRIVER
These license terms are an agreement between you and Microsoft Corporation (or one of its affiliates). They apply to the software named above and any Microsoft services or software updates (except to the extent such services or updates are accompanied by new or additional terms, in which case those different terms apply prospectively and do not alter your or Microsofts rights relating to pre-updated software or services). IF YOU COMPLY WITH THESE LICENSE TERMS, YOU HAVE THE RIGHTS BELOW. BY USING THE SOFTWARE, YOU ACCEPT THESE TERMS.
1. INSTALLATION AND USE RIGHTS.
a) General. You may install and use any number of copies of the software.
b) Included Microsoft Applications. The software may include other Microsoft applications. These license terms apply to those included applications, if any, unless other license terms are provided with the other Microsoft applications.
c) Third Party Components. The software may include third party components with separate legal notices or governed by other agreements, as may be described in the ThirdPartyNotices file(s) accompanying the software.
2. DATA.
a) Data Collection. The software may collect information about you and your use of the software, and send that to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may opt-out of many of these scenarios, but not all, as described in the product documentation.  There are also some features in the software that may enable you to collect data from users of your applications. If you use these features to enable data collection in your applications, you must comply with applicable law, including providing appropriate notices to users of your applications. You can learn more about data collection and use in the help documentation and the privacy statement at https://aka.ms/privacy. Your use of the software operates as your consent to these practices.
b) Processing of Personal Data. To the extent Microsoft is a processor or subprocessor of personal data in connection with the software, Microsoft makes the commitments in the European Union General Data Protection Regulation Terms of the Online Services Terms to all customers effective May 25, 2018, at https://docs.microsoft.com/en-us/legal/gdpr.
3. SCOPE OF LICENSE. The software is licensed, not sold. Microsoft reserves all other rights. Unless applicable law gives you more rights despite this limitation, you will not (and have no right to):
a) work around any technical limitations in the software that only allow you to use it in certain ways;
b) reverse engineer, decompile or disassemble the software, or otherwise attempt to derive the source code for the software, except and to the extent required by third party licensing terms governing use of certain open source components that may be included in the software;
c) remove, minimize, block, or modify any notices of Microsoft or its suppliers in the software;
d) use the software in any way that is against the law or to create or propagate malware; or
e) share, publish, distribute, or lease the software, provide the software as a stand-alone offering for others to use, or transfer the software or this agreement to any third party.
4. EXPORT RESTRICTIONS. You must comply with all domestic and international export laws and regulations that apply to the software, which include restrictions on destinations, end users, and end use. For further information on export restrictions, visit https://aka.ms/exporting.
5. SUPPORT SERVICES. Microsoft is not obligated under this agreement to provide any support services for the software. Any support provided is “as is”, “with all faults”, and without warranty of any kind.
6. UPDATES. The software may periodically check for updates, and download and install them for you. You may obtain updates only from Microsoft or authorized sources. Microsoft may need to update your system to provide you with updates. You agree to receive these automatic updates without any additional notice. Updates may not include or support all existing software features, services, or peripheral devices.
7. ENTIRE AGREEMENT. This agreement, and any other terms Microsoft may provide for supplements, updates, or third-party applications, is the entire agreement for the software.
8. APPLICABLE LAW AND PLACE TO RESOLVE DISPUTES. If you acquired the software in the United States or Canada, the laws of the state or province where you live (or, if a business, where your principal place of business is located) govern the interpretation of this agreement, claims for its breach, and all other claims (including consumer protection, unfair competition, and tort claims), regardless of conflict of laws principles. If you acquired the software in any other country, its laws apply. If U.S. federal jurisdiction exists, you and Microsoft consent to exclusive jurisdiction and venue in the federal court in King County, Washington for all disputes heard in court. If not, you and Microsoft consent to exclusive jurisdiction and venue in the Superior Court of King County, Washington for all disputes heard in court.
9. CONSUMER RIGHTS; REGIONAL VARIATIONS. This agreement describes certain legal rights. You may have other rights, including consumer rights, under the laws of your state, province, or country. Separate and apart from your relationship with Microsoft, you may also have rights with respect to the party from which you acquired the software. This agreement does not change those other rights if the laws of your state, province, or country do not permit it to do so. For example, if you acquired the software in one of the below regions, or mandatory country law applies, then the following provisions apply to you:
a) Australia. You have statutory guarantees under the Australian Consumer Law and nothing in this agreement is intended to affect those rights.
b) Canada. If you acquired this software in Canada, you may stop receiving updates by turning off the automatic update feature, disconnecting your device from the Internet (if and when you re-connect to the Internet, however, the software will resume checking for and installing updates), or uninstalling the software. The product documentation, if any, may also specify how to turn off updates for your specific device or software.
c) Germany and Austria.
i. Warranty. The properly licensed software will perform substantially as described in any Microsoft materials that accompany the software. However, Microsoft gives no contractual guarantee in relation to the licensed software.
ii. Limitation of Liability. In case of intentional conduct, gross negligence, claims based on the Product Liability Act, as well as, in case of death or personal or physical injury, Microsoft is liable according to the statutory law.
Subject to the foregoing clause ii., Microsoft will only be liable for slight negligence if Microsoft is in breach of such material contractual obligations, the fulfillment of which facilitate the due performance of this agreement, the breach of which would endanger the purpose of this agreement and the compliance with which a party may constantly trust in (so-called "cardinal obligations"). In other cases of slight negligence, Microsoft will not be liable for slight negligence.
10. DISCLAIMER OF WARRANTY. THE SOFTWARE IS LICENSED “AS IS.” YOU BEAR THE RISK OF USING IT. MICROSOFT GIVES NO EXPRESS WARRANTIES, GUARANTEES, OR CONDITIONS. TO THE EXTENT PERMITTED UNDER APPLICABLE LAWS, MICROSOFT EXCLUDES ALL IMPLIED WARRANTIES, INCLUDING MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
11. LIMITATION ON AND EXCLUSION OF DAMAGES. IF YOU HAVE ANY BASIS FOR RECOVERING DAMAGES DESPITE THE PRECEDING DISCLAIMER OF WARRANTY, YOU CAN RECOVER FROM MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP TO U.S. $5.00. YOU CANNOT RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL, INDIRECT OR INCIDENTAL DAMAGES.
This limitation applies to (a) anything related to the software, services, content (including code) on third party Internet sites, or third party applications; and (b) claims for breach of contract, warranty, guarantee, or condition; strict liability, negligence, or other tort; or any other claim; in each case to the extent permitted by applicable law.
It also applies even if Microsoft knew or should have known about the possibility of the damages. The above limitation or exclusion may not apply to you because your state, province, or country may not allow the exclusion or limitation of incidental, consequential, or other damages.
Please note: As this software is distributed in Canada, some of the clauses in this agreement are provided below in French.
Remarque: Ce logiciel étant distribué au Canada, certaines des clauses dans ce contrat sont fournies ci-dessous en français.
EXONÉRATION DE GARANTIE. Le logiciel visé par une licence est offert « tel quel ». Toute utilisation de ce logiciel est à votre seule risque et péril. Microsoft naccorde aucune autre garantie expresse. Vous pouvez bénéficier de droits additionnels en vertu du droit local sur la protection des consommateurs, que ce contrat ne peut modifier. La ou elles sont permises par le droit locale, les garanties implicites de qualité marchande, dadéquation à un usage particulier et dabsence de contrefaçon sont exclues.
LIMITATION DES DOMMAGES-INTÉRÊTS ET EXCLUSION DE RESPONSABILITÉ POUR LES DOMMAGES. Vous pouvez obtenir de Microsoft et de ses fournisseurs une indemnisation en cas de dommages directs uniquement à hauteur de 5,00 $ US. Vous ne pouvez prétendre à aucune indemnisation pour les autres dommages, y compris les dommages spéciaux, indirects ou accessoires et pertes de bénéfices.
Cette limitation concerne:
• tout ce qui est relié au logiciel, aux services ou au contenu (y compris le code) figurant sur des sites Internet tiers ou dans des programmes tiers; et
• les réclamations au titre de violation de contrat ou de garantie, ou au titre de responsabilité stricte, de négligence ou dune autre faute dans la limite autorisée par la loi en vigueur.
Elle sapplique également, même si Microsoft connaissait ou devrait connaître léventualité dun tel dommage. Si votre pays nautorise pas lexclusion ou la limitation de responsabilité pour les dommages indirects, accessoires ou de quelque nature que ce soit, il se peut que la limitation ou lexclusion ci-dessus ne sappliquera pas à votre égard.
EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous pourriez avoir dautres droits prévus par les lois de votre pays. Le présent contrat ne modifie pas les droits que vous confèrent les lois de votre pays si celles-ci ne le permettent pas.
DWT 28909236v1 0085000-001126
DWT 28909236v1 0085000-001126

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

10
flask.log Normal file
View File

@ -0,0 +1,10 @@
0.0.0.0:8868 | debug = True
Chromedriver 已安装在 C:\Users\xrilang\.wdm\drivers\chromedriver\win64\126.0.6478.182\chromedriver-win32/chromedriver.exe
0.0.0.0:8868 | debug = True
Chromedriver 已安装在 C:\Users\xrilang\.wdm\drivers\chromedriver\win64\126.0.6478.182\chromedriver-win32/chromedriver.exe
饿了么风神
https://aeolus.ele.me/?targetId=3818#/group/schedule/view/manage
Chromedriver 已安装在 C:\Users\xrilang\.wdm\drivers\chromedriver\win64\126.0.6478.182\chromedriver-win32/chromedriver.exe
Chromedriver 已安装在 C:\Users\xrilang\.wdm\drivers\chromedriver\win64\126.0.6478.182\chromedriver-win32/chromedriver.exe
Chromedriver 已安装在 C:\Users\xrilang\.wdm\drivers\chromedriver\win64\126.0.6478.182\chromedriver-win32/chromedriver.exe
Chromedriver 已安装在 C:\Users\xrilang\.wdm\drivers\chromedriver\win64\126.0.6478.182\chromedriver-win32/chromedriver.exe

3
requirements.txt Normal file
View File

@ -0,0 +1,3 @@
Flask==3.0.3
selenium==4.23.0
webdriver_manager==4.0.1

161
run_window.py Normal file
View File

@ -0,0 +1,161 @@
import configparser
import logging
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.microsoft import EdgeChromiumDriverManager
from webdriver_manager.firefox import GeckoDriverManager
# 读取配置文件
config = configparser.ConfigParser()
config.read('config.ini', encoding="utf-8")
# 从配置文件中读取参数
url_base= config.get('base', 'url_base')
# url_login= config.get('base', 'url_login')
url_login = "https://mozi-login.alibaba-inc.com/?APP_NAME=LPD_TEAM_AEOLUS&BACK_URL=https%3A%2F%2Faeolus.ele.me"
print(url_login)
url_home = config.get('base', 'url_home')
url_work = config.get('base', 'url_work')
account = config.get('base', 'account')
password = config.get('base', 'password')
interval = config.get('base', 'interval')
driver_type = config.get('base', 'driver')
def open_url_with_selenium(url):
# 创建ChromeOptions对象
options = Options()
# 确保无头模式没有被启用
# options.add_argument('--headless') # 注释掉这行
if driver_type.lower()=="firefox":
driver_path = GeckoDriverManager().install()
try:
service = Service(executable_path=driver_path)
driver = webdriver.Firefox(service=service, options=options)
logging.info("成功 - 使用firefox")
except Exception as e:
logging.error("无法创建WebDriver实例: %s", str(e))
return None
elif driver_type.lower()=="edge":
driver_path = EdgeChromiumDriverManager().install()
# 创建WebDriver实例
try:
service = Service(executable_path=driver_path)
driver = webdriver.Edge(service=service, options=options)
logging.info("成功 - 使用edge")
except Exception as e:
logging.error("无法创建WebDriver实例: %s", str(e))
return None
else: # 默认谷歌驱动
# 确保chromedriver已经安装并获取其路径
driver_path = ChromeDriverManager().install()
# 创建Service对象
# 创建WebDriver实例
try:
service = Service(executable_path=driver_path)
driver = webdriver.Chrome(service=service, options=options)
logging.info("成功 - 使用chrome")
except Exception as e:
logging.error("无法创建WebDriver实例: %s", str(e))
return None
try:
# 打开指定的URL
logging.info("开始访问"+url_base)
driver.get(url_base)
sleep(3) # 等待3秒
while True:
if driver.current_url==url_login:
# 填写手机号码
username_field = driver.find_element(By.NAME, 'domainAccount')
username_field.clear()
username_field.send_keys(account)
# 填写密码
password_field = driver.find_element(By.NAME, 'password')
password_field.clear()
password_field.send_keys(password)
# 使用WebDriverWait等待登录按钮变为可点击状态
login_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CLASS_NAME, 'sso-btn-submit'))
)
login_button.click()
# 等待一段时间,确保登录过程完成
sleep(3)
break
print("当前URL", driver.current_url)
print("当前URL", driver.current_url)
while True:
if driver.current_url==url_home:
# 登录成功,已经进入了主页
print("cookie",driver.get_cookies())
# 跳转到 https://aeolus.ele.me/?targetId=3818#/group/schedule/view/manage
driver.get(url_work)
if driver.current_url == url_work:
break
# 开始查找数据
while driver.current_url == url_work:
sleep(interval)
# 查找目标值
# 定位到包含目标完单量的div元素
print("开始查找 - 定位到包含目标完单量的div元素")
div_element = driver.find_element(By.XPATH, "//div[@class='ant-space-item'][2]/span")
print(div_element.text)
print("开始查找 - 定位到包含目标完单量的div元素")
# 定位表格
table = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, ".ant-table-thead")))
# 获取表头
headers = []
header_elements = table.find_elements(By.TAG_NAME, "th")
for header in header_elements:
headers.append(header.text)
print("Headers:", headers)
# 定位表体
tbody = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, ".ant-table-tbody")))
# 获取表体数据
rows = tbody.find_elements(By.TAG_NAME, "tr")
data = []
for row in rows:
cols = row.find_elements(By.TAG_NAME, "td")
row_data = [col.text for col in cols]
data.append(row_data)
print("Data:")
for row in data:
print(row)
# 等待一段时间,确保登录过程完成
sleep(5)
# 检查是否登录成功
if 'login' not in driver.current_url:
print("登录成功!")
else:
print("登录失败,请检查用户名和密码。")
# 返回WebDriver实例而不是关闭它
return driver
except Exception as e:
print(e)
return None
if __name__ == '__main__':
driver = open_url_with_selenium(url_base)
# 如果你想要在后续操作中使用driver可以在这里添加代码
# 例如driver.get('another_url')
# 在你完成所有操作后记得调用driver.quit()来关闭WebDriver实例

121
run_window_v2.py Normal file
View File

@ -0,0 +1,121 @@
import configparser
import logging
import os
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.microsoft import EdgeChromiumDriverManager
from webdriver_manager.firefox import GeckoDriverManager
import ssl
os.environ['WDM_SSL_VERIFY'] = "false"
# 配置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# 读取配置文件
config = configparser.ConfigParser()
config.read('config.ini', encoding="utf-8")
# 从配置文件中读取参数
url_base = config.get('base', 'url_base')
url_login = r"https://mozi-login.alibaba-inc.com/?APP_NAME=LPD_TEAM_AEOLUS&BACK_URL=https%3A%2F%2Faeolus.ele.me"
url_home = config.get('base', 'url_home')
url_work = config.get('base', 'url_work')
account = config.get('base', 'account')
password = config.get('base', 'password')
interval = int(config.get('base', 'interval'))
driver_type = config.get('base', 'driver')
driver_path_edge = config.get('base', 'driver_path_edge')
driver_path_chrome = config.get('base', 'driver_path_chrome')
# WebDriver初始化
def init_webdriver(driver_type):
options = Options()
manager = {
"firefox": GeckoDriverManager,
"edge": EdgeChromiumDriverManager,
"chrome": ChromeDriverManager
}[driver_type.lower()]
driver_path = None # 初始化为None以防安装失败
try:
driver_path = manager().install()
logging.info("找到驱动" + driver_path)
service = Service(executable_path=driver_path)
if driver_type.lower() == "firefox":
oprofile = webdriver.FirefoxOptions()
oprofile.accept_insecure_certs = True
driver = webdriver.Firefox(service=service, options=oprofile)
elif driver_type.lower() == "edge":
driver = webdriver.Edge(service=service, options=options)
else: # chrome
options.add_argument('--ignore-certificate-errors')
driver = webdriver.Chrome(service=service, options=options)
logging.info(f"成功 - 使用{driver_type}")
return driver
except Exception as e:
logging.error(f"无法创建WebDriver实例: {e}")
if driver_type.lower() == "edge" and driver_path_edge: # 只有在Edge类型且路径已知的情况下才尝试使用已存在的驱动
edge_options = Options() # 创建Edge的Options实例
service = Service(executable_path=driver_path_edge) # 使用已知的驱动路径
driver = webdriver.Edge(service=service, options=edge_options) # 传入Options实例
logging.info("使用自行安装的Edge")
return driver
else:
edge_options = Options() # 创建Edge的Options实例
service = Service(executable_path=driver_path_chrome) # 使用已知的驱动路径
driver = webdriver.Edge(service=service, options=edge_options) # 传入Options实例
logging.info("使用自行安装的Chrome")
return driver
# 登录流程
def login(driver, url_login, account, password):
driver.get(url_login)
WebDriverWait(driver, 10).until(EC.url_to_be(url_login))
username_field = driver.find_element(By.NAME, 'domainAccount')
username_field.clear()
username_field.send_keys(account)
password_field = driver.find_element(By.NAME, 'password')
password_field.clear()
password_field.send_keys(password)
login_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CLASS_NAME, 'sso-btn-submit'))
)
login_button.click()
WebDriverWait(driver, 10).until_not(EC.url_to_be(url_login))
logging.info("登录成功!")
# 主要逻辑
def main():
driver = init_webdriver(driver_type)
if driver is None:
logging.error("")
return "驱动异常"
try:
login(driver, url_login, account, password)
driver.get(url_home)
driver.get(url_work)
while driver.current_url == url_work:
sleep(interval)
# 你的数据抓取逻辑
pass
finally:
driver.quit()
if __name__ == '__main__':
main()

3
test.py Normal file
View File

@ -0,0 +1,3 @@
from webdriver_manager.chrome import ChromeDriverManager
print( ChromeDriverManager().install())