from selenium import webdriver from selenium.webdriver.chrome.options import Options#无GUI from selenium.webdriver.common.by import By import time import sys def tianbiao(stuID): chrome_options = Options()#无界面对象 chrome_options.add_argument('--headless') #浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败 chrome_options.add_argument('disable-dev-shm-usage')#禁用-开发-SHM-使用 chrome_options.add_argument('--disable-gpu')#谷歌文档提到需要加上这个属性来规避bug chrome_options.add_argument('no-sandbox') #解决DevToolsActivePort文件不存在的报错 driver = webdriver.Chrome(chrome_options=chrome_options,executable_path='/usr/local/bin/chromedriver') # 表单地址 url = 'http://datawarn9.fdzcxy.edu.cn/datawarn/ReportServer?formlet=app/sanbao.frm&op=h5&userno=' + stuID + '&token=eyJhbGciOiJSUzUxMiJ9.eyJzdWIiOiIyMTIwMDYxOTQiLCJST0xFUyI6IlJPTEVfQURNSU4sYWRtaW5pc3RyYXRvcix1c2VyIiwiY3JlYXRlZCI6MTYwMTM4MjA2MjIzMiwiZXhwIjoxNjA4ODI5Nzk2fQ.hkEyK-ugqOhWmZkx_59RI21lf2kHP2ULDaYPlcbxGEqwNIx44A5Rgf3Rm7mgl6UNeed2Q52xbnBGRcp5itUUjw0IafyxjSJ1o6rNiL4X_yjWOkMNlEF0LppB5VkWBAVCFF8qw4bGXmSkyTI0dHqQxke3wXQkoFPQSGI16ML1648#/form' driver.get(url) # 打开浏览器 time.sleep(2) driver.maximize_window() # 全屏 driver.execute_script("window.scrollTo(0,document.body.scrollHeight);") # 滚动到底部 time.sleep(1) for i in range(1): driver.find_element_by_xpath('//*[@id="app"]/div/div/div[1]/div/div/div/div/div[2]/div/div[1]/div/div[1]/div/div[11]/div[1]/div/input').send_keys('36.6') #昨日午检 driver.find_element_by_xpath('//*[@id="app"]/div/div/div/div/div/div/div/div[2]/div/div[1]/div/div[1]/div/div[13]/div[1]/div/input').send_keys('36.6') #昨日晚检 driver.find_element_by_xpath('//*[@id="app"]/div/div/div[1]/div/div/div/div/div[2]/div/div[1]/div/div[1]/div/div[15]/div[1]/div/input').send_keys('36.6') #昨日晨检 driver.find_element_by_xpath('//*[@id="app"]/div/div/div/div/div/div/div/div[2]/div/div[1]/div/div[1]/div/div[7]/div[1]/div/div/div/div/div/div[2]/div/div').click() #点击校外 driver.find_element_by_xpath('//*[@id="app"]/div/div/div/div/div/div/div/div[2]/div/div[1]/div/div[1]/div/div[23]/div[1]/div').click() #点击提交 time.sleep(2) # 点击确定 #driver.find_element_by_xpath('/html/body/div/div/div/div[2]/div/div[1]/div[1]/div[2]/div/span').click() #time.sleep(1) #time.sleep(2) driver.quit() if __name__ == '__main__': tianbiao(sys.argv[1])
参考