zoukankan      html  css  js  c++  java
  • 疫情无聊,自动打卡程序(py+selenium)

    提要:Firefox引擎(谷歌引擎F12不好用了),选择框内下拉选项,整体页面下拉实现。

    # 导入模块
    from selenium import webdriver
    import random
    from time import sleepXXX

    username = ["XXX"]
    number = ["XXX"]
    phone = ["XXXXXXXXXXXX"]
    temp = ["36.5"]

    # 导入引擎网址
    driver = webdriver.Firefox()
    driver.get("http://xd7wszn1psfa9rfk.mikecrm.com/6bo2dGw")
    # 填空
    driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[4]/div[2]/div/div[1]/input").clear()
    driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[4]/div[2]/div/div[1]/input").send_keys(username[0])
    # 给加载时间
    sleep(2)
    # 整体页面下拉,执行JS语言
    driver.execute_script('window.scrollBy(0,250)')

    driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[5]/div[2]/div/div/i").click()
    sleep(1)
    driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[5]/div[2]/div/div/ul/li[4]/span").click()
    # mouse = driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[5]/div[2]/div/div/i")
    # ActionChains(driver).move_to_element(mouse).perform()
    # driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[5]/div[2]/div/div/ul/li[4]/span").click()

    driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[6]/div[2]/div/div/input").clear()

    driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[6]/div[2]/div/div/input").send_keys(number[0])
    driver.execute_script('window.scrollBy(0,250)')
    driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[8]/div[2]/div/div/div/input").clear()
    driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[8]/div[2]/div/div/div/input").send_keys(phone[0])
    driver.execute_script('window.scrollBy(0,250)')
    # driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[9]/div[2]/div/div[2]/i").click()
    # driver,find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[9]/div[2]/div/div[2]/ul/li[10]").click()
    # driver,find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[9]/div[2]/div/div[3]/i").click()
    # driver,find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[9]/div[2]/div/div[3]/ul/li[9]").click()
    # 下拉双选择框
    driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[9]/div[2]/div/div[2]/i").click()


    ul = driver.find_element_by_css_selector("div.fbc_mlItem:nth-child(2) > ul:nth-child(3)")
    # 最后定位里面所有值
    li = ul.find_elements_by_tag_name('li')
    sleep(0.2)
    # 选取想要的值
    li[0].click() # 0代表选择第一个值
    sleep(1)
    driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[9]/div[2]/div/div[3]/i").click()

    # 然后定位ul
    ul = driver.find_element_by_css_selector("div.fbc_mlItem:nth-child(3) > ul:nth-child(3)")
    # 最后定位里面所有值
    li = ul.find_elements_by_tag_name('li')
    # 选取想要的值
    sleep(0.2)
    li[0].click() # 0代表选择第一个值
    # 选择框完毕
    driver.execute_script('window.scrollBy(0,450)')
    driver.find_element_by_css_selector("#opt203971237 > p:nth-child(1) > svg:nth-child(1) > circle:nth-child(1)").click()
    sleep(0.5)
    driver.find_element_by_css_selector("#opt203971239 > p:nth-child(1) > svg:nth-child(1) > circle:nth-child(1)").click()

    sleep(0.5)
    driver.find_element_by_css_selector("#opt203971241 > p:nth-child(1) > svg:nth-child(1) > circle:nth-child(1)").click()
    sleep(0.5)
    driver.find_element_by_css_selector("#opt203971243 > p:nth-child(1) > svg:nth-child(1) > circle:nth-child(1)").click()
    # 双选完毕
    driver.execute_script('window.scrollBy(0,450)')
    sleep(0.5)
    driver.find_element_by_css_selector("#opt203971245 > p:nth-child(1) > svg:nth-child(1) > circle:nth-child(1)").click()
    sleep(0.5)
    driver.find_element_by_css_selector("#opt203971247 > p:nth-child(1) > svg:nth-child(1) > circle:nth-child(1)").click()
    driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[16]/div[2]/div/div/input").clear()

    driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[16]/div[2]/div/div/input").send_keys(temp[0])
    sleep(0.5)
    driver.find_element_by_css_selector("#opt203971249 > p:nth-child(1) > svg:nth-child(1) > circle:nth-child(1)").click()
    sleep(0.5)
    driver.execute_script('window.scrollBy(0,350)')
    sleep(0.5)
    driver.find_element_by_xpath("//*[@id='form_submit']").click()
    print("Done...")

  • 相关阅读:
    Django 想要单独执行文件
    Django基础
    Bootstrap框架
    Font Awesome矢量图标框架
    js函数式编程——蹦床函数
    ie被hao.360劫持的解决方法
    函数式编程——惰性链
    你可能不知道的BFC在实际中的应用
    高度随宽度适应的响应式方案
    腾讯云播放器更新——TCplayer
  • 原文地址:https://www.cnblogs.com/Knight66666/p/12538870.html
Copyright © 2011-2022 走看看