美文网首页
41. screeshot

41. screeshot

作者: 薛东弗斯 | 来源:发表于2024-03-19 06:20 被阅读0次
    # project > screen.py
    import time
    
    from selenium import webdriver
    from selenium.webdriver import ActionChains
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.select import Select
    
    from utils.get_filepath import get_screen_shot_path
    
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get("https://news.baidu.com/")
    element = driver.find_element(By.CSS_SELECTOR,'a[href="/sh"]')
    driver.execute_script("arguments[0].scrollIntoViewIfNeeded(false);",element)
    driver.save_screenshot(get_screen_shot_path())
    time.sleep(3)
    driver.close()
    
    
    # project > utils > get_file_path.py 
    import os
    import time
    
    def get_logo_path():
        path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))),"file","logo.bmp")
        return path
    
    def get_download_path():
        path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))),"file")
        return path
    
    def get_screen_shot_path():
        file_name = "screen_shot{}_.png".format(time.strftime("%Y-%m-%d_%H-%M-%S"))
        path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "file", file_name)
        return path
    
    # project > file 文件夹用于存放截图文件
    

    相关文章

      网友评论

          本文标题:41. screeshot

          本文链接:https://www.haomeiwen.com/subject/xgsvzdtx.html