zoukankan      html  css  js  c++  java
  • Selenium+python+shell+crontab+firefox

    最近在尝试一个自动打卡的脚本,发现了几个问题,特此记录一下。

    环境:

    Ubuntu 12.04.4 LTS

    selenium 2.43.0

    firefox 32.0.3

    1 本来机器上selenium,firefox都是装过的,但是firefox时不时的就更新一下,所以selenium可能不支持当前的firefox 版本。

    更新 selenium命令:

    sudo pip install -U selenium

    2 使用的Python脚本:

     1 #!/usr/bin/env python
     2 
     3 import sys
     4 from selenium import webdriver
     5 
     6 url = "http://XXX.com/"
     7 driver = webdriver.Firefox()
     8 
     9 driver.get(url+ "/")
    10 driver.find_element_by_xpath("//div[2]/input").send_keys("XXX")
    11 driver.find_element_by_xpath("//div[3]/input").send_keys("XXX")
    12 driver.find_element_by_id("loginButton").click()
    13 driver.find_element_by_css_selector("a > img").click()
    14 
    15 driver.quit()

    3 crontab 自动任务相关命令:

    crontab -l :显示当前用户的定时任务

    crontab -e : 编辑当前用户的定时任务

    实际使用的命令:

    0 18 * * 1-5  export DISPLAY=:0.0 && python /home/yzzw006/Wifi/yzzw_doc/kq.py

    这里有两点需要注意:

     1 因为该任务必须在前台打开浏览器,因此必须加上 “export DISPLAY=:0.0”;

     2 在crontab里执行的脚本地址尽量使用绝对路径

  • 相关阅读:
    [VirtaulBox]网络连接设置
    LeetCode
    LeetCode
    LeetCode
    LeetCode-37.Sudok Solver
    LeetCode-36.Valid Sudoku
    LeetCode-52.N-Queen II
    LeetCode-51.N-Queens
    LeetCode-22.Generate Parentheses
    LeetCode-111.Mininum Depth of Binary Tree
  • 原文地址:https://www.cnblogs.com/yzzw006/p/4016170.html
Copyright © 2011-2022 走看看