• 【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
  • 相关阅读:
    wxpython快速入门
    python核心编程 第四章 和第五章
    python核心编程 第三章
    python核心编程 第二章 快速入门
    Nginx 使用札记
    PHP 函数总结
    node.js安装部署
    linux
    在Linux上安装Git
    php超级全局变量
  • 原文地址:https://www.cnblogs.com/jingsheng99/p/9147540.html
Copyright © 2020-2023  润新知