挂号自动化脚本思路
登录华西医院网页。
browser = webdriver.Chrome()#进入网址browser.get('http://guahao.wchscu.cn/file/h5/index.html#/')
自动登录,向手机发送验证码,等待输入后登录
#点击登录browser.find_element(By.CLASS_NAME,"el-button--primary").click()#输入手机号input_user=browser.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/div[1]/div/div[2]/uni-view/form/div[1]/div/div/input')input_user.send_keys('电话号码')#发送手机验证码while True: if browser.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/div[1]/div/div[2]/uni-view/form/div[1]/div/div/div/button'): browser.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/div[1]/div/div[2]/uni-view/form/div[1]/div/div/div/button').click() print('请登录') break
进入倒计时
while True: now=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') print(now) #时间对比 if now >= '2023-02-24 10:15:00': break
到时进入医生主页
#医生主页某某=r'http://guahao.wchscu.cn/file/h5/index.html#/pages/doctorInfor/index?'browser.get(某某)
确定预约进入预约界面
while 1==1: try: if browser.find_element(By.CLASS_NAME,'el-button--primary'): browser.find_element(By.CLASS_NAME,'el-button--primary').click() print('确定预约') break except: pass
选择健康卡并获取图形码
#选择电子卡while 1==1: try: if browser.find_element(By.XPATH,'//table[@class="el-table__body"]'): browser.find_element(By.XPATH,'//table[@class="el-table__body"]').click() print('选择电子卡') break except: pass#获取验证码while 1==1: try: if browser.find_element(By.XPATH,'//div[@class="el-input-group__append"]/button'): browser.find_element(By.XPATH,'//div[@class="el-input-group__append"]/button').click() print('获取验证码') break except: pass
利用ddddocr包识别图形码并输入
##########识别图片二维码#定位到验证码元素,因为验证码是以base64格式while 1==1: try: if browser.find_element(By.XPATH,'//img'): el=browser.find_element(By.XPATH,'//img') print('找到识别码') break except: pass#将当前元素的屏幕截图保存为png图像文件el.screenshot('./image.png')#识别验证码ocr=ddddocr.DdddOcr()with open("image.png","rb") as f: image=f.read()res=ocr.classification(image)#定位元素,输入验证码browser.find_element(By.XPATH,'//input[@placeholder="请输入验证码"]').send_keys(res)print('输入识别码')#browser.find_element(By.CLASS_NAME,'el-button--primary').click()
最后确认并结束
while 1==1: try: if browser.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/div/div/div[3]/span/button[2]'): browser.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/div/div/div[3]/span/button[2]').click() print('抢号结束') break except: pass
完整代码链接如下
示例
py医院挂号
来源地址:https://blog.csdn.net/qq_43029008/article/details/129195840