代码如下
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()