2017-04-19 7 views
0

이것은 시도한 코드입니다. 다른 stackoverflow 페이지에서 얻었지만 작동하지 않았습니다. 왜 어떤 아이디어?python 셀레늄은 요소에서 스크린 샷을 저장합니다.

chrome = webdriver.Chrome() 
chrome.get('http://stackoverflow.com/') 

# now that we have the preliminary stuff out of the way time to get that image :D 
element = chrome.find_element_by_class_name('-img') # find part of the page you want image of 
location = element.location 
size = element.size 
chrome.save_screenshot('screenshot.png') # saves screenshot of entire page 
chrome.quit() 

raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: cannot get automation extension from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html (Session info: chrome=57.0.2987.133) (Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 10.0.10586 x86_64)

편집 :

raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: cannot get automation extension from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html (Session info: chrome=57.0.2987.133) (Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 10.0.10586 x86_64)

+0

업데이트 크롬 드라이버에 대한 스크린 샷을 캡처이

그냥 element.save_screenshot("file name")를 호출 할 수있는 방법을 제공하고있다 –

답변

0

당신은 당신의 chromedriver을 업데이트해야합니다 : 는

from selenium import webdriver 
from selenium.webdriver.chrome.options import Options 


chrome_options = Options() 
chrome_options.add_argument("--disable-extensions") 
chrome = webdriver.Chrome(chrome_options=chrome_options) 

chrome.get('http://stackoverflow.com/') 

# now that we have the preliminary stuff out of the way time to get that image :D 
element = chrome.find_element_by_class_name('-img') # find part of the page you want image of 
location = element.location 
size = element.size 
chrome.save_screenshot('screenshot.png') # saves screenshot of entire page 
chrome.quit() 

오류 시도. 크롬 드라이버가 오래되었다고 생각합니다. 귀하의 질문을 바탕으로

, 당신이 요소를 스크린 샷 싶습니다, 현재 셀레늄은 특정 요소