Radiation2001 2022-05-06 12:38 采纳率: 100%
浏览 45
已结题

python实现自动微信端预约,请问除了以下预约思路,还有其他快速的思路吗

问题遇到的现象和发生背景

学校微信端预约程序,手动抢根本抢不到,12点开网站,12:00:03全部被预约,于是想通过python实现快速自动化预约。

问题相关代码,请勿粘贴截图

```python
from selenium.webdriver.common.by import By
import json
import os
import time
from selenium.common.exceptions import NoSuchElementException
import time

from selenium.webdriver.chrome.service import Service

from selenium import webdriver

import time

s = Service(r'C:\Program Files\Google\Chrome\Application\chromedriver.exe')
driver = webdriver.Chrome(service=s)
driver.implicitly_wait(3)
driver.get('http://gym.ujs.edu.cn/index.php/index/yuyue/list.html?item_id=3')#打开预约网址
driver.delete_all_cookies()
time.sleep(1)

向浏览器添加保存的cookies

cookies = json.load(open("cookies.txt", "rb"))
for cookie in cookies:
cookie_dict = {
"domain": cookie.get('domain'),
'name': cookie.get('name'),
'value': cookie.get('value'),
"expires": "",
'path': '/',
'httpOnly': True,
'HostOnly': False,
'Secure': False}
driver.add_cookie(cookie_dict)

driver.refresh()

button =driver.find_elements_by_class_name('weui-btn weui-btn_primary')

driver.find_element_by_class_name('weui-btn weui-btn_primary').click()

driver.find_element(by=By.LINK_TEXT,value='登录').click()
time.sleep(0.5)

driver.find_element_by_class_name('office-time-item slot_').click()

driver.find_element(by=By.XPATH,value="//div[@class='office-time-item slot_' and @data-id='3']").click()
driver.find_element(by=By.LINK_TEXT,value='选择场地').click()
driver.find_element(by=By.XPATH,value="//div[@class='office-time-item area_' and @area-id='17']").click()
time.sleep(0.5)
#测试代码

driver.find_element(by=By.XPATH,value="//div[@class='office-time-item timeslot_ disable' and @data-id='6856']").click()

#实际运行代码
driver.find_element(by=By.XPATH,value="//div[@class='office-time-item timeslot_ able' and @data-id='6856']").click()
driver.find_element(by=By.LINK_TEXT,value='立即支付').click()

```python
import pyautogui
import time

FAILSAFE = False
xy = pyautogui.locateOnScreen('sport.png', confidence=0.7) #
center = pyautogui.center(xy) # 寻找图片的中心
pyautogui.click(center)
def actionA():

# xy = pyautogui.locateOnScreen('sport.png',confidence=0.7)  #
# center = pyautogui.center(xy)  # 寻找图片的中心
# pyautogui.click(center)
pyautogui.scroll(-400)
time.sleep(1)
pyautogui.scroll(-400)
xy = pyautogui.locateOnScreen('load.png',confidence=0.7)  #
center = pyautogui.center(xy)  # 寻找图片的中心
pyautogui.click(center)
time.sleep(0.5)
xy = pyautogui.locateOnScreen('back.png', confidence=0.7)  #
center = pyautogui.center(xy)  # 寻找图片的中心
pyautogui.click(center)
pyautogui.moveRel(0, 50, duration=0.25)
pyautogui.scroll(-400)

def actionB():
pyautogui.scroll(-400)
time.sleep(1)
xy = pyautogui.locateOnScreen('yumaoqiu.png',confidence=0.7) #
center = pyautogui.center(xy) # 寻找图片的中心
pyautogui.click(center)
pyautogui.scroll(-400)
time.sleep(1)
xy = pyautogui.locateOnScreen('choose.png',confidence=0.7) #
center = pyautogui.center(xy) # 寻找图片的中心
pyautogui.click(center)

time.sleep(1)
pyautogui.scroll(-800)
xy = pyautogui.locateOnScreen('sujiao.png',grayscale=True,confidence=0.8)  #
center = pyautogui.center(xy)  # 寻找图片的中心
pyautogui.click(center)
pyautogui.scroll(-400)

xy = pyautogui.locateOnScreen('eight.png',confidence=0.7)  #
center = pyautogui.center(xy)  # 寻找图片的中心
pyautogui.click(center)
pyautogui.scroll(-400)
xy = pyautogui.locateOnScreen('zhifu.png',confidence=0.9)  #
center = pyautogui.center(xy)  # 寻找图片的中心
pyautogui.click(center)

while True:
if pyautogui.locateOnScreen('yumaoqiu.png',confidence=0.7):
actionB()
print("预约成功")

else:
    pyautogui.scroll(-400)
    actionA()
    print("执行预约")
    pyautogui.scroll(-400)
运行结果及报错内容

思路一:selenium自动化,结果支付端必须要求在微信端上,失败
思路二:利用pyautogui自动识图点击模拟微信端,速度适中,置信度设置0.7还能将就,但是由于网站12点才开启,代码编写过程中发现逻辑有问题,会一直执行else下的刷新而不执行函数B下的预约程序。暂时搁置

我的解答思路和尝试过的方法

方法如思路一与思路二

我想要达到的结果

想要实现微信端自动化,还能有其他精确快速的方法吗?或者思路二的逻辑怎么样修改?

  • 写回答

1条回答 默认 最新

  • aabbabababaa 2022-05-06 14:33
    关注

    秒抢啊,确定程序能秒执行

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 5月14日
  • 已采纳回答 5月6日
  • 创建了问题 5月6日

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决