zoukankan      html  css  js  c++  java
  • 【Python】混合驱动实例

    keywords2.txt:
    get||ie||{urls.txt}
    get||chrome||http://www.iciba.com
    
    main.py:
    from selenium import webdriver
    import time
    import re
    
    def get(browser_type,url,i):
        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")
        driver.get(url)
        #截屏保存
        screenpic=driver.get_screenshot_as_file(r"e:\test4\"+"screenPic"+str(i)+".png")
        time.sleep(3)
        driver.quit()
    
    with open("keywords2.txt") as f:
        for line in f:
            action,browser_type,url=tuple(line.strip().split("||"))
            if re.search(r"{(.*)}",url):
                file_name=re.search(r"{(.*)}",url).group(1)
                with open(file_name) as fp:
                    i=0
                    for url in fp:
                        command=action+"('"+browser_type+"','"+url.strip()+"','"+str(i)+"')"
                        #print command
                        i+=1
                        try:
                            exec(command)
                        except Exception,e:
                            print e
            else:
                i=3
                command=action+"('"+browser_type+"','"+url.strip()+"','"+str(i)+"')"
                try:
                    exec(command)
                except Exception,e:
                    print e
  • 相关阅读:
    少儿编程之图形编程
    少儿编程是什么?要学吗?如何学?
    AlloyDesigner 使用
    轮播总结
    git实用攻略
    git subtree用法(转)
    vue 插值,v-once,v-text, v-html
    webpack的学习准备工作
    webstorm中github的配置
    less 安装和webstorm的使用
  • 原文地址:https://www.cnblogs.com/jingsheng99/p/9147540.html
Copyright © 2011-2022 走看看