zoukankan      html  css  js  c++  java
  • 【Python】数字驱动

    #练习1:打开3个网址,每个等3秒钟

    urls.txt:

    http://www.baidu.com
    http://www.sogou.com
    http://www.sohu.com

    main.py:
    from selenium import webdriver
    import time

    driver = webdriver.Chrome(executable_path = "c:\chromedriver")
    with open("urls.txt") as fp: #urls.txt里存三个网址
    for url in fp:
    driver.get(url)
    time.sleep(3)
    driver.current_url
    driver.quit()

     1 #练习2:通过命令行选择浏览器或文件打开和执行
     2 urls.txt:
     3 http://www.baidu.com
     4 http://www.sogou.com
     5 http://www.sohu.com
     6 
     7 main.py:
     8 #python test.py chrome  http://www.sohu.com
     9 #python test.py ie  urls.txt
    10 
    11 from selenium import webdriver
    12 import sys
    13 import time
    14 
    15 if len(sys.argv)!=3:
    16     print "parameter number is not valid!"
    17     sys.exit()
    18 
    19 browser_type=sys.argv[1]
    20 file_or_url=sys.argv[2]
    21 
    22 if browser_type.lower()=="chrome":
    23     driver = webdriver.Chrome(executable_path = "c:\chromedriver")
    24 elif browser_type.lower()=="ie":
    25     driver = webdriver.Ie(executable_path = "c:\IEDriverServer")
    26 else:
    27     driver = webdriver.Firefox(executable_path = "c:\geckodriver")
    28 
    29 if file_or_url.find("http://")!=-1:
    30     driver.get(file_or_url)
    31 else:
    32     with open(path) as fp: #urls.txt里存三个网址
    33         for url in fp:
    34             driver.get(url)
    35             time.sleep(3)
    36             driver.current_url
    37 driver.quit() 
  • 相关阅读:
    documentFragment文档碎片
    OpenResty之resty.limit.count 模块介绍
    vue前端分页多条件搜索
    element ui Tree树形控件获取未全选父节点和子节点id
    如何使 pdf 文件在浏览器里面直接下载而不是打开
    关于本博客
    圆锥曲线基础知识点
    NOI2021游记
    20210716模拟赛
    计数+动态规划
  • 原文地址:https://www.cnblogs.com/jingsheng99/p/9131411.html
Copyright © 2011-2022 走看看