【发布时间】:2016-12-03 02:29:46
【问题描述】:
我用 Python 和 Selenium 制作了一个网页浏览器脚本。
我正在编写脚本,所以它会执行一项功能,即有 60 秒的冷却时间,然后继续执行第二项功能(无需等待 60 秒的冷却时间)。
我正在寻找一种解决方案,我可以在其中执行第一个任务,在进入下一个功能时开始倒计时(也有 100 秒的冷却时间),为此启动一个计时器,然后循环钻孔程序(在永恒)。
代码:
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
username = input("Type your username: ")
password = input("Type in your password: ")
#Opening Firefox
driver = webdriver.Firefox()
#Logging in
def login():
driver.get("http://website.com")
un = driver.find_element_by_name("username")
un.send_keys(username)
pw = driver.find_element_by_name("password")
pw.send_keys(password)
login = driver.find_element_by_name("login")
login.click()
def first():
driver.get("http://website.com/page1")
po = driver.find_element_by_id("id_1")
po.click() #Have to wait 60 sec before i can repeat this step
def second():
driver.get("http://website.com/page2")
pt = driver.find_element_by_id("id_2")
pt.click() #Have to wait 100 sec before i can repeat this step
login()
first() #I want this
second() #and this function to repeat themselves until i cancel the script
有人能帮我解决这个问题吗?
抱歉解释不好。
任何帮助都将不胜感激!
【问题讨论】:
标签: python python-3.x selenium