【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()
 #练习2:通过命令行选择浏览器或文件打开和执行
urls.txt:
http://www.baidu.com
http://www.sogou.com
http://www.sohu.com main.py:
#python test.py chrome http://www.sohu.com
#python test.py ie urls.txt from selenium import webdriver
import sys
import time if len(sys.argv)!=:
print "parameter number is not valid!"
sys.exit() browser_type=sys.argv[]
file_or_url=sys.argv[] if browser_type.lower()=="chrome":
driver = webdriver.Chrome(executable_path = "c:\\chromedriver")
elif browser_type.lower()=="ie":
driver = webdriver.Ie(executable_path = "c:\\IEDriverServer")
else:
driver = webdriver.Firefox(executable_path = "c:\\geckodriver") if file_or_url.find("http://")!=-:
driver.get(file_or_url)
else:
with open(path) as fp: #urls.txt里存三个网址
for url in fp:
driver.get(url)
time.sleep()
driver.current_url
driver.quit()
上一篇:GreenPlum的Primary和Mirro切换恢复


下一篇:SpringBoot+Mybatis+ Druid+PageHelper 实现多数据源并分页