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=new' 然后扩展可以工作但整页不工作 而且我已经尝试过'--headless = chrome'...扩展不起作用..
Message: unknown error: failed to wait for extension background page to load
我已经向下滚动了!