一、正则案例1:获取用例失败编号
error_number.py
# coding=utf-8 """ 作者:gaojs 功能: 新增功能: 日期:2022/6/13 17:58 """ import re import requests import os.path import time from selenium import webdriver def get_error_case_number(module): """ 正则获取失败用例编号 """ if not os.path.exists('error'): os.mkdir('error') url = f'http://[192::1:192]/cgi-bin/test_report.pl?build=netIAG_3_2_0_6_gaojs_708&module={module}&result=fail' resp = requests.get(url) # print(resp.text) result = re.findall(r'[0-9]{10}.py', resp.text) for num in result: # 只要数字部分 num = num.split('.')[0] with open(f'error/{module}_err.txt', mode='a') as fin: fin.write(num + '\n') print(num) def get_fail_aaa_all(module): """ selenium获取失败的http用例标号 """ if not os.path.exists('error'): os.mkdir('error') url = f'http://[192::1:192]/cgi-bin/test_report.pl?build=netIAG_3_2_0_6_gaojs_703&module={module}&result=fail' driver = webdriver.Chrome() driver.get(url) driver.maximize_window() if os.path.exists(f'error/{module}_err'): os.remove(f'error/{module}_err') time.sleep(5) for i in range(2, 300): try: result = driver.find_element_by_xpath(f'/html/body/form/table[2]/tbody/tr[{i}]/td[1]/a').text print(result) # 分别写在对应的文件 # with open(f'error/aaa_err_{module}', mode='w') as fin: # 卸载同一个文件 with open(f'error/{module}_err', mode='a') as fin: # fin.write(result + '\n') except: pass driver.close() if __name__ == '__main__': get_error_case_number('http') # get_fail_aaa_all('http') # get_fail_aaa_all('radius') # get_fail_aaa_all('ldap') # get_fail_aaa_all('saml') # get_fail_aaa_all('tcptunnel')
二、正则案例2:自动下载release
get_release.py
#!/bin/bash # coding=utf-8 """ 作者:gaojs 功能: 新增功能: 日期:2022/7/11 14:29 """ import os.path import re import requests def get_release(): """ 正则匹配版本号 """ url = 'http://10.3.0.120/sp2/build/rel_netiag_10_0_4.html' resp = requests.get(url) # print(resp.text) base_url = re.findall(r'http:\/\/10\.3\.0\.120\/sp2\/build\/nodebug-Rel_NetIAG_[0-9]_[0-9]_[0-9]_[0-9]\.click', resp.text)[0] print(base_url) base_name = os.path.split(base_url)[1] os.chdir('/var/www/html/builds/netIAG/') if not os.path.exists('/var/www/html/builds/' + base_name): os.system(r'curl -o %s %s' % (base_name, base_url)) print('*********************** 下载完成 **********************') if __name__ == '__main__': get_release()