中药普查实物管理系统,腊叶标本和药材标本,无法上传文件,如何解决

这几天帮助安安师兄整理中药普查的数据,遇到一个问题,中药普查实物管理系统添加腊叶标本和药材标本无法上传文件,只能一条一条添加。于是我使用Selenium + ChromeDriver编写自动化程序解决这一问题。
需要自取,有问题请留言。
运行环境:win10,python3.7;
Chrome驱动:根据chrome版本下载chromedriver驱动;
第三方库:selenium ,pandas
加载必要的包

from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
import time

打开网页并登录

# 打开网页
driver_path=r"E:\Program Data\chromedriver_win32\chromedriver.exe"
driver=webdriver.Chrome(executable_path=driver_path)
driver.get('http://sw.zyzypc.com.cn/ycypsubedit.aspx')
# 登录
driver.find_element_by_xpath('/html/body/div[1]/form/input[1]').send_keys('你的账号名')
driver.find_element_by_xpath('/html/body/div[1]/form/input[2]').send_keys('你的密码')
driver.find_element_by_xpath('/html/body/div[1]/form/button[1]').click()
time.sleep(1)

逐条上传腊叶标本

# 读取文件
file = r'E:\ly.xls'
data = pd.read_excel(file,sheet_name=1,header=0)
print(data.columns)
# 上传
driver.find_element_by_xpath('//*[@id="sidebar-collapse"]/ul/li[2]/a').click()
time.sleep(1)
for i in range(len(data)):  
	# 点击添加
    while(1):
        if driver.find_element_by_xpath('//*[@id="btn_add"]').is_displayed():
            driver.find_element_by_xpath('//*[@id="btn_add"]').click()
            break   
    # 填写信息
    time.sleep(1)
    driver.find_element_by_xpath('//*[@id="tiaomahao"]').clear()
    driver.find_element_by_xpath('//*[@id="tiaomahao"]').send_keys(data.iloc[i]['采集号'])
    driver.find_element_by_xpath('//*[@id="caijihao"]').click()
    time.sleep(1)
    if data.iloc[i]['标本状态(花)'] == '√':
        driver.find_element_by_xpath('//*[@id="hua_1"]').click()
    else:
        driver.find_element_by_xpath('//*[@id="hua_0"]').click() 
    if data.iloc[i]['标本状态(果)'] == '√':  
        driver.find_element_by_xpath('//*[@id="guo_1"]').click()
    else:
        driver.find_element_by_xpath('//*[@id="guo_0"]').click() 
    driver.find_element_by_xpath('//*[@id="number"]').clear()
    driver.find_element_by_xpath('//*[@id="parid"]').clear()
    time.sleep(1)
    driver.find_element_by_xpath('//*[@id="number"]').send_keys(int(data.iloc[i]['数量']))
    driver.find_element_by_xpath('//*[@id="parid"]').send_keys(int(data.iloc[i]['箱号']))
    time.sleep(1)
    driver.find_element_by_xpath('//*[@id="btnedit"]').click()
    # 确认完成
    while(1):
        if EC.alert_is_present()(driver):
            test_alert = driver.switch_to.alert        
            test_alert.accept()
            print(data.iloc[i]['采集号'],'完成')
            break

逐条上传药材标本

# 读取文件
file = r'E:\yc.xls'
data = pd.read_excel(file,sheet_name=1,header=0)
print(data.columns)
# 上传药材标本
driver.find_element_by_xpath('//*[@id="sidebar-collapse"]/ul/li[3]/a').click()
time.sleep(1)
for i in range(54,len(data)):  
    # 点击添加
    while(1):
        if driver.find_element_by_xpath('//*[@id="btn_add"]').is_displayed():
            driver.find_element_by_xpath('//*[@id="btn_add"]').click()
            break   
    # 填写信息
    time.sleep(1) 
    driver.find_element_by_xpath('//*[@id="tiaomahao"]').clear()
    driver.find_element_by_xpath('//*[@id="tiaomahao"]').send_keys(data.iloc[i]['采集号'])
    driver.find_element_by_xpath('//*[@id="caijihao"]').click()
    time.sleep(1)
    
    driver.find_element_by_xpath('//*[@id="ycweight"]').clear()
    driver.find_element_by_xpath('//*[@id="parid"]').clear()
    time.sleep(1)   
    driver.find_element_by_xpath('//*[@id="ycweight"]').send_keys(str(data.iloc[i]['重量']))
    driver.find_element_by_xpath('//*[@id="parid"]').send_keys(int(data.iloc[i]['箱号']))
    time.sleep(1)
    driver.find_element_by_xpath('//*[@id="btnedit"]').click()
    # 确认完成
    while(1):
        if EC.alert_is_present()(driver):
            test_alert = driver.switch_to.alert        
            test_alert.accept()
            print(data.iloc[i]['采集号'],'完成')
            break

参考文章:
https://www.cnblogs.com/Jacck/p/7784915.html
https://www.jianshu.com/p/b64e92d0aae6
https://www.cnblogs.com/yoyoketang/p/6569170.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值