简单的混合驱动

数据文件:

创新互联建站是一家专业从事网站建设、做网站、网页设计的品牌网络公司。如今是成都地区具影响力的网站设计公司,作为专业的成都网站建设公司,创新互联建站依托强大的技术实力、以及多年的网站运营经验,为您提供专业的成都网站建设、营销型网站建设及网站设计开发服务!

testdata.txt

visit||http://www.bing.com
visit||${e:\urls.txt}

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

#encoding=utf-8
from selenium import webdriver
import re

driver = webdriver.Chrome(executable_path="d:\\chromedriver")

def visit(url):
    global driver
    driver.get(url)

def main(filepath):
    with open(filepath) as fp:
        for line in fp:
            if line.strip():
                if re.search(r"\${(.*?)}",line):
                    action = line.split("||")[0]
                    data_file = re.search(r"\${(.*?)}",line).group(1)
                    with open(data_file)  as file_obj:
                        for url in  file_obj:
                            command = "%s('%s')" %(action,url.strip())
                            eval(command)

                else:
                    action = line.split("||")[0]
                    url = line.split("||")[1].strip()
                    command = "%s('%s')" %(action,url)
                    eval(command)

if __name__ == "__main__":
    main("E:\\python\\自动化\\testdata.txt")
    driver.quit()

分享文章:简单的混合驱动
标题来源:http://pwwzsj.com/article/jghgcc.html