• 通过不同的浏览器来启动不同的线程.py


    from threading import Thread
    from selenium import webdriver
    from time import ctime,sleep
    #测试用例
    def test_baidu(browser,search):
    print("start:%s" % ctime())
    print("browser:%s" % browser)
    if browser == "ie":
    driver = webdriver.Ie()
    elif browser == "chrome":
    driver = webdriver.Chrome()
    elif browser == "ff":
    driver = webdriver.Firefox()
    else:
    print("browser参数有误,只能为ie、ff、chrome")
    driver.get("http://www.baidu.com")
    driver.find_element_by_id("kw").send_keys(search)
    driver.find_element_by_id("su").click()
    sleep(2)
    driver.quit()

    if __name__ == '__main__':
    #启动参数:
    lists = {"chrome":"threading","ie":"webdriver","ff":"python"}
    threads = []
    files = range(len(lists))
    #创建线程
    for browser,search in lists.items():
    t = Thread(target=test_baidu,args=(browser,search))
    threads.append(t)
    #启动线程
    for t in files:
    threads[t].start()
    for t in files:
    threads[t].join()
    print("end:%s" % ctime())
  • 相关阅读:
    【洛谷P1330】封锁阳光大学
    【洛谷P1087】FBI树
    hdu 4504(动态规划)
    hdu 4503(数学,概率)
    hdu 5400(思路题)
    hdu 5701(区间查询思路题)
    hdu 4502(DP)
    hdu 1401(单广各种卡的搜索题||双广秒速)
    hdu 1258(DFS)
    hdu 1254(搜索题)
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12210558.html
Copyright © 2020-2023  润新知