Python+selenium 隐藏浏览器+截图

代码如下

from selenium import webdriver
#隐藏浏览器
chrome_opts=webdriver.ChromeOptions()
chrome_opts.add_argument("--headless")
#Chromedriver存放路径
path='C:\\Users\\wb-yjh525621\\Downloads\\chromedriver_win32\\chromedriver.exe'
driver=webdriver.Chrome(path,chrome_options=chrome_opts)
try:
    driver.get("http://www.baidu.com")
    driver.find_element_by_id('kw').send_keys('12306')
    #截图
    driver.get_screenshot_as_file("D:\\baidu12306.png")
except RuntimeError as error:
    print(error)
finally:
    driver.quit()

 

上一篇:selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to


下一篇:Windows 2016 安装Sharepoint 2016 预装组件失败