def scroll_to_bottom(driver):
prev_height = driver.execute_script("return window.scrollY")
while True:
driver.execute_script("window.scrollBy(0, 500);")
time.sleep(0.5)
new_height = driver.execute_script("return window.scrollY")
if new_height == prev_height:
break
prev_height = new_height
chrome_options = webdriver.ChromeOptions()
script_path = os.path.abspath(__file__)
naver_pass_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(script_path))),'screenshot', 'jojlddfolpiejckahpinefdikdogenjg.crx')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-popup-blocking')
chrome_options.add_argument('--load-extension=C:/Users/user/AppData/Local/Google/Chrome/User Data/Profile/Extensions/jojlddfolpiejckahpinefdikdogenjg/1.6.0_0')
chrome_service = ChromeService()
driver = webdriver.Chrome(service=chrome_service, options=chrome_options)
url = 'https://m.cafe.naver.com/musiclord/1087911'#sys.argv[1]
driver.get(url)
time.sleep(3)
scroll_to_bottom(driver)
width = driver.execute_script("return Math.max( document.body.scrollWidth, document.body.offsetWidth, document.documentElement.clientWidth, document.documentElement.scrollWidth, document.documentElement.offsetWidth );")
height = driver.execute_script("return Math.max( document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight );")
driver.set_window_size(width, height)
screenshot_file = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(script_path))),'screenshot', 'take_picture', 'resource', 'screenshot.png')
driver.save_screenshot(screenshot_file)
driver.quit()
我想截图整个页面。我需要申请延期…但是,如果我headless为true整页,扩展不应用,而且,当我无头假的扩展,整个页面不工作。我怎样才能……?(headless=new不工作)
我已经尝试了'——headless=new',然后扩展是工作的,但整个页面不工作我已经试过"-headless=chrome"了……分机不起作用…Message: unknown error: failed to wait for extension background page to load
我已经向下滚动了!
你可以在启动webdriver时最大化页面
options = ChromeOptions()
options.add_argument("--start-maximized")