import pandas as pd
import time
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
df = pd.read_excel('student_grades.xlsx')
print(df.head())
driver = Chrome()
for idx,row in df.iterrows():
url = 'http://antpython.net/webspider/grade_form'
driver.get(url)
# 已提交数据
WebDriverWait(driver,5).until(lambda d: "已提交数据" in d.page_source)
姓名 = row['姓名']
driver.find_element(By.XPATH,'//*[@id="sname"]').send_keys(姓名)
time.sleep(0.2)
语文成绩 = row['语文成绩']
driver.find_element(By.XPATH, '// *[ @ id = "yuwen"]').send_keys(语文成绩)
time.sleep(0.2)
数学成绩 = row['数学成绩']
driver.find_element(By.XPATH, '// *[ @ id = "shxue"]').send_keys(数学成绩)
time.sleep(0.2)
英语成绩 = row['英语成绩']
driver.find_element(By.XPATH, '//*[@id="yingyu"]').send_keys(英语成绩)
time.sleep(0.2)
driver.find_element(By.XPATH, '// *[ @ id = "submit_button"]').click()
print(姓名,语文成绩,数学成绩,英语成绩)
WebDriverWait(driver, 5).until(lambda d: "提交成功" in d.page_source)
driver.close()
``
Python读取Excel数据自动提交网页表单
最新推荐文章于 2024-06-07 00:37:08 发布