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...")

  • 相关阅读:
    获取窗口句柄
    人生路上要懂得“刹车”(转)
    关于打开外部程序并且发送一个按键消息 (转)
    CString 和 char * 的相互转换
    iOS开发之了解iPhone中Get和Post方式(转)
    一些简单的Python代码,尝尝Python啥味道 (转)
    iphone 使用委托(delegate)在不同的窗口之间传递数据(转)
    UITextView控件的用法详解 (转)
    iPhone起步1: "Hello,World!" in iPhone Development (转)
    【引用】iphone xml解析流程
  • 原文地址:https://www.cnblogs.com/Knight66666/p/12538870.html
Copyright © 2011-2022 走看看