2022 西安某宁 3V3 男子单打 A 组 到底有多卷呢?

selenium 库pip install selenium


chromedriver.exe 放在 C:\Users\Administrator\AppData\Local\Programs\Python\Python36 中测试代码
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://www.baidu.com/')
OCR 使用微信的提取文字或 QQ 的屏幕识图,此处略。
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
user_names = ['王靖淇', '段沅龙', '蒋宇', '刘嘉鑫', '李翊辰', '乔佳辉', '周惠一', '唐天毅', '覃禹阳', '郭珂', '付迪雄', '王新洛', '张邈汉', '张竟超', '朱恩亮',
'范泽洋', '高嘉炜', '余纪霖', '杨博', '毛立凯', '何非凡', '李鹏辉', '刘俊延', '张玥涵', '王嘉华', '党楚京', '李浩杰', '白晨阳', '郭容義', '万鑫豪',
'孙阳', '常皓焜', '赵亮', '柏维昭', '谢少石', '刘新', '房龙昊', '王为初', '耿智浩', '刘灵桦', '吴瑞隆', '许磊', '曹先龙', '吕彤璞', '苏武松',
'朱子曦', '李成敏', '宋振庭', '李龙玥', '范森', '刘智宇', '赵士滕', '杨烨', '王逸伦', '王梓宸', '甘士杰', '张廷全', '刘国洋', '张艺威', '张嘉豪',
'崔鹏', '李龙', '柴洮', '白津昊', '梁志文', '焦子熠', '穆桐', '杨泽宇', '王禄', '雷宇', '张哲珩', '王凯弘', '张鑫', '付磊', '刘一鸣', '王雅帅',
'梁健伟', '苏铭', '李佳轩', '胥子豪', '王焕军', '柏承钊', '张晓', '胡晓斌', '杨海林', '陈振刚', '邓秦龙', '吕李宝', '吕锦博', '易畅', '李姚',
'刘腾飞', '孙启轩', '刘文泽', '张伯龙', '王哲', '李国京', '高伟']
# Chrome配置
option = webdriver.ChromeOptions()
option.add_experimental_option('useAutomationExtension', False)
option.add_experimental_option('excludeSwitches', ['enable-automation'])
driver = webdriver.Chrome(options=option)
# 爬取逻辑
count = 0
for user_name in user_names:
driver.get(f'https://ydydj.univsport.com/index.php?c=look&a=seach_look&item=36.1&user_name={user_name}')
# 显式等待5s,查找class为main_lista的元素
main_lista = WebDriverWait(driver, 5).until(lambda x: x.find_element(By.CLASS_NAME, 'main_lista'))
elements = main_lista.find_elements(By.XPATH, './*') # 查找底下的所有元素
if elements:
count += 1
for element in elements:
# 简略版
# text = element.text
# level = text.splitlines()[-1]
# print(user_name, level)
# 详细版
element.click()
time.sleep(2)
wza_rigys = driver.find_element(By.CLASS_NAME, 'wza_rigys')
texts = wza_rigys.text.splitlines()
data = {x.replace(':', ''): texts[i + 1] for i, x in enumerate(texts) if ':' in x} # 具体等级信息
print(data['姓名'], data['等级'], data['比赛名称'], data['比赛成绩'], data['授予时间'])
else:
print(user_name)
print(f'参赛{len(user_names)}人,其中等级运动员{count}人,占比 {count / len(user_names) * 100:.2f}%')
driver.close()
参赛 98 人,其中等级运动员 21 人,占比 21.43%

PS:可能有重名的人存在,例如孙阳