gpt4 book ai didi

python - 使用 selenium python 截取整个页面截图

转载 作者:行者123 更新时间:2023-12-04 01:03:54 27 4
gpt4 key购买 nike

我正在尝试使用 selenium 和 chromedriver 截取整页屏幕截图,但我得到了这个半截屏。我尝试过其他方法,但到目前为止只有这个有效,并且只需要半页截图。
任何人都可以使用另一个技巧来解决这个问题,也可以附上输出结果。
Page Screenshot

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


options = webdriver.ChromeOptions()
options.headless = True
driver = webdriver.Chrome(options=options)

URL = "http://stevens.ekkel.ai"

driver.get(URL)

S = lambda X: driver.execute_script('return document.body.parentNode.scroll'+X)
driver.set_window_size(S('Width'),S('Height')) # May need manual adjustment
driver.find_element_by_tag_name('body').screenshot('web_screenshot.png')

driver.quit()

最佳答案

我正在使用 PyPI 包:Selenium-Screenshot您可以使用命令 - pip install Selenium-Screenshot 安装它
可以在此处找到此包的详细信息:https://pypi.org/project/Selenium-Screenshot/
分享一个关于如何使用这个包进行整页截图的示例补丁:

from Screenshot import Screenshot_Clipping

#Saving screenshot
ob=Screenshot_Clipping.Screenshot()
img=ob.full_Screenshot(driver,save_path=r'D:/OneDrive -Libin/Python/Sel_python/Pytest/Screenshots',image_name="Screenshot1.png")

driver.close()
driver.quit()
检查截图供您引用: /image/opgPi.png

关于python - 使用 selenium python 截取整个页面截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67147412/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com