当前位置:网站首页>Selenium batch query athletes' technical grades

Selenium batch query athletes' technical grades

2022-06-23 21:36:00 XerCis

Problem description

2022 Xi'an mouning 3V3 Men's singles A Group How many volumes are there ?




install

  1. Python Of selenium library
pip install selenium
  1. install Chrome
  2. View this machine Chrome Version number
  3. install Chrome drive
    Search according to the version number Google browser drive image or The official driver

    After decompressing chromedriver.exe Put it in C:\Users\Administrator\AppData\Local\Programs\Python\Python36 in

Test code

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://www.baidu.com/')




Code

OCR Use wechat to extract text or QQ Screen map of , Here slightly .

Selenium + Athlete technical grade information inquiry system

import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

user_names = [' Wang Jingqi ', ' Duanyuanlong ', ' Jiang Yu ', ' Liujiaxin ', ' Li Yichen ', ' Qiaojiahui ', ' Zhouhuiyi ', ' Tangtianyi ', ' Qin Yuyang ', ' Guo Ke ', ' Fudixiong ', ' Wangxinluo ', ' Zhangmiaohan ', ' Zhang Jingchao ', ' Zhu enliang ',
              ' Fanzeyang ', ' Gaojiawei ', ' Yujilin ', ' Yang Bo ', ' Maolikai ', ' He Feifan ', ' Li Penghui ', ' Liu Junyan ', ' Zhangyuehan ', ' Wang Jiahua ', ' Dang Chujing ', ' Li Haojie ', ' Bai Chenyang ', ' Guorongyi ', ' Wanxinhao ',
              ' Sun Yang ', ' Chang Haokun ', ' Zhao Liang ', ' Baiweizhao ', ' Xie Shaoshi ', ' Liu Xin ', ' Fanglonghao ', ' Wang Weichu ', ' Gengzhihao ', ' Liulinghua ', ' Wuruilong ', ' Xu Lei ', ' Caoxianlong ', ' Lvtongpu ', ' Suwusong ',
              ' Zhuzixi ', ' Li Chengmin ', ' Songzhenting ', ' Lilongyue ', ' Fanson ', ' Liuzhiyu ', ' Zhaoshiteng ', ' Yang Ye ', ' Wangyilun ', ' Wangzichen ', ' Ganshijie ', ' Zhangtingquan ', ' Liuguoyang ', ' Zhang Yiwei ', ' Zhang Jiahao ',
              ' Cui Peng ', ' Li Long ', ' Chaitao ', ' Bai Jinhao ', ' Liangzhiwen ', ' Jiaoziyi ', ' Mutong ', ' Yangzeyu ', ' Wang Lu ', ' Lei Yu ', ' Zhangzheheng ', ' Wangkaihong ', ' Zhang Xin ', ' Fu Lei ', ' Yi-ming liu ', ' Wangyashuai ',
              ' Liangjianwei ', ' Su Ming ', ' Li Jiaxuan ', ' Xuzihao ', ' Wang Huanjun ', ' Baichengzhao ', ' Zhang Xiao ', ' Huxiaobin ', ' Yang Hailin ', ' Chenzhengang ', ' Dengqinlong ', ' LV Libao ', ' Lvjinbo ', ' Easy ', ' Li Yao ',
              ' Liu Tengfei ', ' Sunqixuan ', ' Liuwenze ', ' Zhangbolong ', ' Wang Zhe ', ' Liguojing ', ' Gao Wei ']

# Chrome To configure 
option = webdriver.ChromeOptions()
option.add_experimental_option('useAutomationExtension', False)
option.add_experimental_option('excludeSwitches', ['enable-automation'])
driver = webdriver.Chrome(options=option)

#  Crawling logic 
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}')
    #  Explicit waiting 5s, lookup class by main_lista The elements of 
    main_lista = WebDriverWait(driver, 5).until(lambda x: x.find_element(By.CLASS_NAME, 'main_lista'))
    elements = main_lista.find_elements(By.XPATH, './*')  #  Find all the elements below 
    if elements:
        count += 1
        for element in elements:
            #  Abridged edition 
            # text = element.text
            # level = text.splitlines()[-1]
            # print(user_name, level)

            #  A detailed version 
            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}  #  Specific level information 
            print(data[' full name '], data[' Grade '], data[' The name of the game '], data[' score '], data[' Time of grant '])
    else:
        print(user_name)
print(f' Competition {
      len(user_names)} people , Among them, level athletes {
      count} people , Proportion  {
      count / len(user_names) * 100:.2f}%')
driver.close()

Competition 98 people , Among them, level athletes 21 people , Proportion 21.43%

PS: There may be people with the same name , For example, Sun Yang




reference

  1. Selenium Documentation
  2. webdriver Got an element , How to get all the child nodes and parent nodes under this element
  3. Selenium There are three ways to set element waiting
  4. 2022 Xi'an mouning 3V3 Men's singles A Group
原网站

版权声明
本文为[XerCis]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231849368215.html