CQI365
CQI365

CQI365 Continuous Quality improvement in Life and Work 365 days a year

透過Selenium 完成Google Form 自動填寫

如何透過Selenium 完成google form 填寫

 這幾個月公司每天都要上線填體溫與TOCC,但實際上每天關在家中哪裡都沒去,每天的TOCC都一樣。體溫基本上也都在正常範圍。為了不要每天填寫TOCC,因此我寫了一個script來Automate整個填寫過程。真的可以說,懶惰是進步的動力。

主要工具:Selenium。

Selenium 主要透過模擬瀏覽器,來完成一些網頁操作的任務。因此很適合操作性的網頁自動化。相對比爬蟲是在做抓取資料以提供後續分析,兩者不太一樣!

ps. 要透過selenium 來啟動瀏覽器,要注意一下使用的瀏覽器種類,並去該瀏覽器的網站下載driver。

Code:

from selenium import webdriver
import random
from datetime import datetime
year = datetime.now().year
month = datetime.now().month
day = datetime.now().day
driver = webdriver.Edge(‘C:/WebDriver/bin/msedgedriver’)
driver.get(‘https://docs.google.com/…’)
date_check = driver.find_elements_by_xpath(“//div[contains(@class,’quantumWizTextinputPaperinputContentArea exportContentArea’)]//input”)[0]
date_check.send_keys(year, month, day)
position_Check = driver.find_element_by_xpath(“//div[@class=’appsMaterialWizToggleRadiogroupEl exportToggleEl’ and @id=’i12']”)
position_Check.click()
code_check = driver.find_elements_by_xpath(“//div[contains(@class,’quantumWizTextinputPaperinputContentArea exportContentArea’)]//input”)[1]
code_check.send_keys(‘XXXXX’)
name_check = driver.find_elements_by_xpath(“//div[contains(@class,’quantumWizTextinputPaperinputContentArea exportContentArea’)]//input”)[2]
name_check.send_keys(‘XXX’)
travel_Check = driver.find_element_by_xpath(
“//div[@class=’appsMaterialWizToggleRadiogroupEl exportToggleEl’ and @id=’i51']”)
travel_Check.click()
contact_Check = driver.find_element_by_xpath(“//div[@class=’appsMaterialWizToggleRadiogroupEl exportToggleEl’ and @id=’i65']”)
contact_Check.click()
temeprature = str(round(random.uniform(35.8, 37), 1))
temperature_check = driver.find_elements_by_xpath(“//div[contains(@class,’quantumWizTextinputPaperinputContentArea exportContentArea’)]//input”)[5]
temperature_check.send_keys(temeprature)
submit = driver.find_elements_by_xpath(“//div[@role=’button’]”)[0]
submit.click()
driver.close()

封裝與自動化

最後將上述得程式封裝成exe檔,並透過window安排自動化排定執行時間。這樣就搞定了繁瑣的TOCC。


透過Selenium 完成Google Form 自動填寫 - CQI365 - Medium

CC BY-NC-ND 2.0 版权声明

喜欢我的文章吗?
别忘了给点支持与赞赏,让我知道创作的路上有你陪伴。

加载中…
加载中…

发布评论